Skip to content

REF: implement Dtype.index_class #54511

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 3 commits into from
Aug 16, 2023

Conversation

jbrockmendel
Copy link
Member

Allows EAs to specify what Index subclass they want to use. Avoids special-casing pandas-internal EAs.

Small perf improvement

In [2]: dti = pd.date_range("2016-01-01", periods=3, tz="UTC")

In [3]: cat = dti.astype("category")

In [4]: %timeit pd.Index(dti)
6.39 µs ± 80 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each) # <- main
5.69 µs ± 368 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)  # <- PR

In [5]: %timeit pd.Index(cat)
6.37 µs ± 112 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)  # <- main
5.8 µs ± 135 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)  # <- PR

@@ -671,6 +675,12 @@ def _get_common_dtype(self, dtypes: list[DtypeObj]) -> DtypeObj | None:

return find_common_type(non_cat_dtypes)

@cache_readonly
Copy link
Member

Choose a reason for hiding this comment

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

Could you make these properties like the base class?

Copy link
Member Author

Choose a reason for hiding this comment

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

updated to make both cache_readonly; I think the perf improvement in the OP depends on 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.

Updated + greenish

@mroeschke mroeschke added Refactor Internal refactoring of code ExtensionArray Extending pandas with custom dtypes or arrays. labels Aug 15, 2023
@mroeschke mroeschke added this to the 2.2 milestone Aug 16, 2023
@mroeschke mroeschke merged commit 203f483 into pandas-dev:main Aug 16, 2023
@mroeschke
Copy link
Member

Thanks @jbrockmendel

@jbrockmendel jbrockmendel deleted the ref-index-methods branch August 16, 2023 18:27
mroeschke pushed a commit to mroeschke/pandas that referenced this pull request Aug 18, 2023
* REF: implement Dtype.index_class

* property->cache_readonly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ExtensionArray Extending pandas with custom dtypes or arrays. Refactor Internal refactoring of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants