-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Implement PeriodIndex.difference without object-dtype cast #30697
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
Conversation
pandas/_testing.py
Outdated
@@ -619,7 +619,10 @@ def _get_ilevel_values(index, level): | |||
# accept level number only | |||
unique = index.levels[level] | |||
level_codes = index.codes[level] | |||
filled = take_1d(unique.values, level_codes, fill_value=unique._na_value) | |||
if is_extension_array_dtype(unique): |
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.
this is not as nice (though its only for testing), won't unique.take(...) work here?
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.
ill give it a shot
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.
Turns out this unique.take(...) wont work here. the trouble is that we are calling _shallow_copy below (presumably for perf) and using unique.take ends up passing the wrong types to shallow_copy
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.
using unique.take ends up passing the wrong types to shallow_copy
then i'd rather not change this, take_1d just does the right thing, so why change it?
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.
Looks like passing unique._values instead of unique.values fixes the problem cleanly
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.
ok great
lgtm ping on green. |
thanks |
Analogous to #30666. After this we'll be able to share some code between the set operations.
The edit in pd._testing is mostly unrelated. Both are motivated by tracking down the places where object-dtype ndarray is passed to PeriodIndex._shallow_copy.