Skip to content

REF: reverse dispatch in factorize #49966

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
Dec 1, 2022

Conversation

jbrockmendel
Copy link
Member

  • closes #xxxx (Replace xxxx with the GitHub issue number)
  • Tests added and passed if fixing a bug or adding a new feature
  • All code checks passed.
  • Added type annotations to new arguments/methods/functions.
  • Added an entry in the latest doc/source/whatsnew/vX.X.X.rst file if fixing a bug or adding a new feature.

Needed for upcoming removal of DTA/TDA.freq

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

Looks good, just left a couple of comments for my own understanding

if isinstance(self, ABCIndex):
# preserve e.g. NumericIndex, preserve MultiIndex
uniques = self._constructor(uniques)
else:
Copy link
Member

Choose a reason for hiding this comment

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

does this change from elif isinstance(self, ABCSeries) because here self would always be ABCSeries, so it might as well just be else?

Copy link
Member Author

Choose a reason for hiding this comment

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

correct

Comment on lines -746 to -747
if not isinstance(values, ABCMultiIndex):
values = extract_array(values, extract_numpy=True)
Copy link
Member

Choose a reason for hiding this comment

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

is this no longer necessary because of the early return above

   if isinstance(values, (ABCIndex, ABCSeries)):
        return values.factorize(sort=sort, use_na_sentinel=use_na_sentinel)

?

Copy link
Member Author

Choose a reason for hiding this comment

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

correct


if isinstance(self, ABCIndex):
# preserve e.g. NumericIndex, preserve MultiIndex
uniques = self._constructor(uniques)
Copy link
Member

Choose a reason for hiding this comment

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

what's the reason to change this from

            uniques = ensure_wrapped_if_datetimelike(uniques)
            uniques = self._shallow_copy(uniques, name=None)

? Is it just simpler?

Copy link
Member Author

Choose a reason for hiding this comment

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

correct

@MarcoGorelli MarcoGorelli added the Refactor Internal refactoring of code label Nov 30, 2022
@MarcoGorelli MarcoGorelli added this to the 2.0 milestone Nov 30, 2022
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks @jbrockmendel !

@mroeschke mroeschke merged commit d1d8b66 into pandas-dev:main Dec 1, 2022
@mroeschke
Copy link
Member

Thanks @jbrockmendel

@jbrockmendel jbrockmendel deleted the ref-factorize branch December 1, 2022 02:53
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.

3 participants