Skip to content
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

Merged
merged 2 commits into from
Feb 24, 2018

Conversation

cbertinato
Copy link
Contributor

Categories and ordering of the resulting Series were not the same as those of the passed Categorical dtype. Closes #19565

  • tests added / passed
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

@gfyoung gfyoung added Reshaping Concat, Merge/Join, Stack/Unstack, Explode Categorical Categorical Data Type labels Feb 15, 2018
@codecov
Copy link

codecov bot commented Feb 16, 2018

Codecov Report

Merging #19717 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 89.98% <100%> (-0.01%) ⬇️
#single 41.79% <0%> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/dtypes/cast.py 87.98% <100%> (ø) ⬆️
pandas/util/testing.py 83.64% <0%> (-0.21%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8382067...47f7d40. Read the comment docs.

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Feb 16, 2018

Could you also add a test that hits the Series constructor directly?

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.

@@ -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)
Copy link
Member

@jschendel jschendel Feb 16, 2018

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)

Copy link
Contributor Author

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.

Categories and ordering of the resulting Series were not the same as those of the passed Categorical dtype
@jreback jreback added this to the 0.23.0 milestone Feb 24, 2018
@jreback jreback merged commit 26dd5b1 into pandas-dev:master Feb 24, 2018
@jreback
Copy link
Contributor

jreback commented Feb 24, 2018

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Categorical Categorical Data Type Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants