Subclassing pandas.Index · Issue #15258 · pandas-dev/pandas (original) (raw)
@spencerkclark is working on a custom pandas.Index
subclass for xarray (see pydata/xarray#1084) like pandas.DatetimeIndex
to handle arrays of netcdftime.datetime
objects. This index is primarily intended for use with xarray, but ideally we'd like it to work in pandas Series
and DataFrame
objects, too.
The subclass will include implementations of at least get_loc
, get_slice_bound
and get_value
(this one should probably be unnecessary, but it's needed for pandas.Series
). To minimize fragility, it will not subclass DatetimeIndex
but will instead copy some of the relevant code (thank you open source!).
Two questions for other pandas devs:
- Is there any fundamental reason why a custom
pandas.Index
subclass won't work on aSeries
orDataFrame
? - Does this seem like a reasonable thing to do, or we are setting ourselves up for suffering in the future? I'll update this issue when we have a concrete PR to look at.
At a bare minimum, we should probably add some tests to pandas to ensure that a basic subclass works.