-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Subclassing pandas.Index #15258
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
there are already quite a few subclasses of Indexes (internally). The API is not publicly exposed. I think it would take a bit of work to make it 'simpler'. You have to define a fair bit of machinery (lots of methods) to make it work properly. Including construction, inference, equality, testing, and various indexing routines. It is thus straightforward, but not trivial to sub-class. (remember IntervalIndex!)
It will work. though there may be some API leakage (IOW some methods are 'internal', others are 'public form the main pandas API).
why do you think you need a custom Index? |
Indeed, I do :)
The climate science community wants the convenient indexing of |
@shoyer ok in that case I would directly subclass As I said above, you might have some API leakage (IOW, we have a notion of pandas functions calling Index methods which are not 'public' per se). But nothing insurmountable. So comes down do you need: points-in-time, or spans. |
@spencerkclark is working on a custom
pandas.Index
subclass for xarray (see pydata/xarray#1084) likepandas.DatetimeIndex
to handle arrays ofnetcdftime.datetime
objects. This index is primarily intended for use with xarray, but ideally we'd like it to work in pandasSeries
andDataFrame
objects, too.The subclass will include implementations of at least
get_loc
,get_slice_bound
andget_value
(this one should probably be unnecessary, but it's needed forpandas.Series
). To minimize fragility, it will not subclassDatetimeIndex
but will instead copy some of the relevant code (thank you open source!).Two questions for other pandas devs:
pandas.Index
subclass won't work on aSeries
orDataFrame
?At a bare minimum, we should probably add some tests to pandas to ensure that a basic subclass works.
The text was updated successfully, but these errors were encountered: