Skip to content

REF: use array_algos shift for Categorical.shift #33663

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 1 commit into from
Apr 20, 2020

Conversation

jbrockmendel
Copy link
Member

We have duplicate code in Categorical.shift and Categorical.take that can be refactored out into Categorical._validate_fill_value (which is the name that DTA/TDA/PA use for the same method, which I intend to share eventually, xref #33660). From there the rest of Categorical.shift can dispatch to array_algos.transforms.shift.

The logic changed here is a TypeError becoming a ValueError (which matches what DTA/TDA/PA do)

@jreback jreback added the Refactor Internal refactoring of code label Apr 20, 2020
@jreback jreback added this to the 1.1 milestone Apr 20, 2020
@@ -10,6 +10,10 @@
def shift(values: np.ndarray, periods: int, axis: int, fill_value) -> np.ndarray:
new_values = values

if periods == 0:
# TODO: should we copy here?
return new_values
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should, do we elsewhere?

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 we currently do a copy in 1/2 of places where this is called

@jreback
Copy link
Contributor

jreback commented Apr 20, 2020

lgtm. comment (can merge and followon or do here).

@jbrockmendel
Copy link
Member Author

(can merge and followon or do here).

Will do follow-up to make the copy consistent (and occur in exactly one place)

@jreback jreback merged commit 9376960 into pandas-dev:master Apr 20, 2020
@jreback
Copy link
Contributor

jreback commented Apr 20, 2020

(can merge and followon or do here).

Will do follow-up to make the copy consistent (and occur in exactly one place)

gr8

@jbrockmendel jbrockmendel deleted the cate-shift branch April 20, 2020 01:35
CloseChoice pushed a commit to CloseChoice/pandas that referenced this pull request Apr 20, 2020
rhshadrach pushed a commit to rhshadrach/pandas that referenced this pull request May 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Refactor Internal refactoring of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants