Skip to content

Subclassing pandas.Index #15258

Closed
Closed
@shoyer

Description

@shoyer

@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 a Series or DataFrame?
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementSubclassingSubclassing pandas objectsTestingpandas testing functions or related to the test suite

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions