-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
Deprecate IntervalIndex.from_intervals in favor of the IntervalIndex constructor #19263
Comments
lets do option 1 and deprecate |
+1. A few things become easier if we can get rid of the special cases for fooIndex._constructor, which this would be a step towards. |
What was the original motivation to add this? |
@jorisvandenbossche I would ask you the reverse question? why have another method of constructing things. |
@shoyer I know you prefer the |
In the original design the IntervalIndex constructor looked like So I agree that we don't need the separate I will also add that I'm slightly puzzled by why we have a |
Was actually going to open an issue regarding this later today, but will share my thoughts here too. There are a couple corner cases where In [2]: pd.IntervalIndex([], closed='both')
Out[2]:
IntervalIndex([]
closed='both',
dtype='interval[int64]')
In [3]: pd.IntervalIndex([np.nan, np.nan], closed='neither')
Out[3]:
IntervalIndex([nan, nan]
closed='neither',
dtype='interval[float64]') This currently isn't supported (it's what the issue I'm planning to open is about), but I'm of the opinion that we should allow users to override the inferred In [4]: ii = pd.interval_range(0, 3)
In [5]: ii
Out[5]:
IntervalIndex([(0, 1], (1, 2], (2, 3]]
closed='right',
dtype='interval[int64]')
In [6]: pd.IntervalIndex(ii, closed='both', dtype='interval[float64]') # dtype changes, closed ignored
Out[6]:
IntervalIndex([(0.0, 1.0], (1.0, 2.0], (2.0, 3.0]]
closed='right',
dtype='interval[float64]')
In [7]: pd.IntervalIndex(ii.values, closed='both', dtype='interval[float64]') # closed raises
---------------------------------------------------------------------------
ValueError: conflicting values for closed: constructor got 'both', inferred from data 'right' |
Can we add |
Adding In [2]: ii1 = pd.interval_range(0, 3, closed='left')
In [3]: ii2 = pd.interval_range(0, 3, closed='right')
In [4]: ii1.dtype == ii2.dtype
Out[4]: True That being said, I'm not sure it'd be best to remove the |
Currently, the
IntervalIndex
constructor andIntervalIndex.from_intervals
essentially have the same functionality: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 thatIntervalIndex.from_intervals
does not.Seems like there are a few options to clean things up:
from_intervals
to the constructorfrom_intervals
, and redirect the constructor tofrom_intervals
fastpath
from_intervals
entirely, and only use the constructorI'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.The text was updated successfully, but these errors were encountered: