Skip to content

Deprecate IntervalIndex.from_intervals in favor of the IntervalIndex constructor #19263

Closed
@jschendel

Description

@jschendel

Currently, the IntervalIndex constructor and IntervalIndex.from_intervals essentially have the same functionality:

In [2]: ivs = [pd.Interval(0, 1), pd.Interval(2, 3)]

In [3]: pd.IntervalIndex(ivs)
Out[3]:
IntervalIndex([(0, 1], (2, 3]]
              closed='right',
              dtype='interval[int64]')

In [4]: pd.IntervalIndex.from_intervals(ivs)
Out[4]:
IntervalIndex([(0, 1], (2, 3]]
              closed='right',
              dtype='interval[int64]')

However, both are using independent code to do this, which seems redundant. This has also led to two being slightly out of sync, as the IntervalIndex constructor supports a few more parameters (dtype, closed) and has some additional checks that IntervalIndex.from_intervals does not.

Seems like there are a few options to clean things up:

  1. Move all code to the constructor, and redirect from_intervals to the constructor
  2. Move all construction code to from_intervals, and redirect the constructor to from_intervals
    • Would still have some constructor specific behavior, e.g. fastpath
  3. Remove from_intervals entirely, and only use the constructor
  4. Something else?

I'm leaning towards 1, as it looks like that's what eventually happens elsewhere for other from_* methods, e.g. Categorical.from_codes, MultiIndex.from_product. Don't really have a strong opinion though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeprecateFunctionality to remove in pandasIntervalInterval data type

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions