Deprecate IntervalIndex.from_intervals in favor of the IntervalIndex constructor · Issue #19263 · pandas-dev/pandas (original) (raw)
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:
- Move all code to the constructor, and redirect
from_intervals
to the constructor - Move all construction code to
from_intervals
, and redirect the constructor tofrom_intervals
- Would still have some constructor specific behavior, e.g.
fastpath
- Would still have some constructor specific behavior, e.g.
- Remove
from_intervals
entirely, and only use the constructor - 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.