-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: pandas.Index
cannot be subclassed (despite saying it can be in the docs)
#37882
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
Comments
I confirm the issue on master. Ever overriding
Output:
|
Index is not trivially subclasses and needs a fair amount of hooks welcome to have a fully working example but you would have to dive into the current implementation not sure subclassing makes a whole lot of sense generally |
@jreback Would love an example of how to do this if possible! |
well someone would need to write the docs after understanding how it could work and of course out testing inplace for doing this arbitrarily so welcome pull requests |
The xarray project actually has an Index subclass (see https://github.com/pydata/xarray/blob/23dc2fc9f2785c348ff821bf2da61dfa2206d283/xarray/coding/cftimeindex.py), which I think is actively being used Now, the main issue that is shown above by the small examples is that you can't subclass |
@jorisvandenbossche Thanks this makes sense! |
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample, a copy-pastable example
The result is:
<class 'pandas.core.indexes.numeric.Int64Index'> Int64Index([1, 2, 3], dtype='int64')
Problem description
In the
pandas
docs: "The motivation for having an Index class in the first place was to enable different implementations of indexing. This means that it’s possible for you, the user, to implement a custom Index subclass that may be better suited to a particular application than the ones provided in pandas."Expected Output
<class 'CustomIndex'> CustomIndex([1, 2, 3], dtype='int64')
Output of
pd.show_versions()
The text was updated successfully, but these errors were encountered: