Skip to content

CLN: remove CategoricalIndex._create_from_codes #36342

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
Sep 13, 2020

Conversation

jbrockmendel
Copy link
Member

Update some constructor calls in Categorical

@@ -211,29 +211,6 @@ def __new__(

return cls._simple_new(data, name=name)

def _create_from_codes(self, codes, dtype=None, name=None):
Copy link
Member

Choose a reason for hiding this comment

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

rather than delete this, could this be something like

def _create_from_codes(self, codes, name=None):
    name = name if name else self.name
    cat = self._data._from_backing_data(codes)
    return type(self)._simple_new(cat, name=name)

Copy link
Member Author

Choose a reason for hiding this comment

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

it only saves 1 line, and id rather have fewer constructor methods

Copy link
Member

Choose a reason for hiding this comment

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

don't we have the same code duplicated 4 times. (except that name should be lib._no_default 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.

yes. the ongoing process is to share more of this with the other ndarray-backed-ea-indexes

Copy link
Member

Choose a reason for hiding this comment

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

ahh. so instead of the parameter name being codes it would be more generic? wouldn't this give more opportunities for de-duplication and all numpy backed indexes could have a _create_from_codes called say ``_from_backing_data` to be consistent with the underlying array

Copy link
Member Author

Choose a reason for hiding this comment

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

im hopeful but not there yet. theres a lot of special cases in the DTI/TDI code because of .freq

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah the purpose is to avoid special casing things as much as possible; here the constructor is special cases.

@simonjayhawkins simonjayhawkins added this to the 1.2 milestone Sep 13, 2020
@simonjayhawkins simonjayhawkins added Categorical Categorical Data Type Refactor Internal refactoring of code labels Sep 13, 2020
@jreback jreback merged commit 3007baf into pandas-dev:master Sep 13, 2020
@jbrockmendel jbrockmendel deleted the cln-create_from_codes branch September 13, 2020 20:26
kesmit13 pushed a commit to kesmit13/pandas that referenced this pull request Nov 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Categorical Categorical Data Type Refactor Internal refactoring of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants