Skip to content

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

Merged
merged 4 commits into from
Jan 5, 2020

Conversation

jbrockmendel
Copy link
Member

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.

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

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?

Copy link
Member Author

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

Copy link
Member Author

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

Copy link
Contributor

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?

Copy link
Member Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok great

@jreback jreback added Period Period data type Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Jan 4, 2020
@jreback jreback added this to the 1.0 milestone Jan 4, 2020
@jreback
Copy link
Contributor

jreback commented Jan 4, 2020

lgtm ping on green.

@jreback jreback merged commit 69e2cc5 into pandas-dev:master Jan 5, 2020
@jreback
Copy link
Contributor

jreback commented Jan 5, 2020

thanks

@jbrockmendel jbrockmendel deleted the ref-pi-sets2 branch January 5, 2020 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Period Period data type Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants