-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: fix Series constructor for scalar and Categorical dtype #19717
Conversation
Codecov Report
@@ Coverage Diff @@
## master #19717 +/- ##
==========================================
- Coverage 91.61% 91.6% -0.01%
==========================================
Files 150 150
Lines 48882 48882
==========================================
- Hits 44782 44780 -2
- Misses 4100 4102 +2
Continue to review full report at Codecov.
|
Could you also add a test that hits the result = Series('a', index=[0, 1],
dtype=pd.api.types.CategoricalDtype(['a', 'b'], ordered=True) That way if the implementation changes in the future, we at least have that covered. |
pandas/core/dtypes/cast.py
Outdated
@@ -1178,7 +1178,8 @@ def construct_1d_arraylike_from_scalar(value, length, dtype): | |||
subarr = DatetimeIndex([value] * length, dtype=dtype) | |||
elif is_categorical_dtype(dtype): | |||
from pandas import Categorical | |||
subarr = Categorical([value] * length) | |||
subarr = Categorical([value] * length, dtype.categories, | |||
ordered=dtype.ordered) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be done more concisely with Categorical([value] * length, dtype=dtype)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do. I'll add a test for the Series constructor. @jschendel good point. I'll make that change as well.
1276dad
to
e33967f
Compare
Categories and ordering of the resulting Series were not the same as those of the passed Categorical dtype
e33967f
to
1357680
Compare
thanks! |
Categories and ordering of the resulting Series were not the same as those of the passed Categorical dtype. Closes #19565
git diff upstream/master -u -- "*.py" | flake8 --diff