-
- Notifications
You must be signed in to change notification settings - Fork 19.4k
Description
Code Sample, a copy-pastable example if possible
IntervalIndexconstructor ignoresclosedparameter for purely NA data:
In [3]: pd.IntervalIndex([np.nan], closed='both') Out[3]: IntervalIndex([nan] closed='right', dtype='interval[float64]') In [4]: pd.IntervalIndex([np.nan, np.nan], closed='neither') Out[4]: IntervalIndex([nan, nan] closed='right', dtype='interval[float64]')This only occurs on master, as it appears to be an over-correction resulting from the fix in #18340
IntervalIndexalso ignoresclosedwhen it conflicts with the how the input data is closed:
In [6]: ivs = [pd.Interval(0, 1, closed='both'), pd.Interval(10, 20, closed='both')] In [7]: pd.IntervalIndex(ivs, closed='neither') Out[7]: IntervalIndex([[0, 1], [10, 20]] closed='both', dtype='interval[int64]')The behavior above occurs on master, and is a result of #18340. The opposite behavior occurred prior, where intervals would always be coerced to match the closed specified by the constructor. Should probably raise when the constructor vs. inferred closed conflict.
- Inconsistent dtype for empty
IntervalIndexdepending on the method of construction:
In [2]: pd.IntervalIndex([]).dtype Out[2]: interval[object] In [3]: pd.IntervalIndex.from_intervals([]).dtype Out[3]: interval[object] In [4]: pd.IntervalIndex.from_breaks([]).dtype Out[4]: interval[float64] In [5]: pd.IntervalIndex.from_tuples([]).dtype Out[5]: interval[float64] In [6]: pd.IntervalIndex.from_arrays([], []).dtype Out[6]: interval[float64]Expected Output
-
IntervalIndexconstructor should not ignore theclosedparameter for purely NA data (since it can't inferclosedfrom the input data). -
IntervalIndexshould raise when given conflictingclosedvs. inferredclosedfrom data. -
IntervalIndexshould have the same dtype for empty data regardless of the method of construction. It's not immediately clear to me which dtype should be used, but my feeling isinterval[object]since that's the behavior of the constructor/from_intervals.