51
51
default_pprint ,
52
52
ensure_index ,
53
53
maybe_extract_name ,
54
- unpack_nested_dtype ,
55
54
)
56
55
from pandas .core .indexes .datetimes import DatetimeIndex , date_range
57
56
from pandas .core .indexes .extension import ExtensionIndex , inherit_names
@@ -157,7 +156,6 @@ def wrapped(self, other, sort=False):
157
156
158
157
>>> pd.interval_range(start=0, end=5)
159
158
IntervalIndex([(0, 1], (1, 2], (2, 3], (3, 4], (4, 5]],
160
- closed='right',
161
159
dtype='interval[int64, right]')
162
160
163
161
It may also be constructed using one of the constructor
@@ -242,7 +240,6 @@ def _simple_new(cls, array: IntervalArray, name: Label = None):
242
240
--------
243
241
>>> pd.IntervalIndex.from_breaks([0, 1, 2, 3])
244
242
IntervalIndex([(0, 1], (1, 2], (2, 3]],
245
- closed='right',
246
243
dtype='interval[int64, right]')
247
244
"""
248
245
),
@@ -273,7 +270,6 @@ def from_breaks(
273
270
--------
274
271
>>> pd.IntervalIndex.from_arrays([0, 1, 2], [1, 2, 3])
275
272
IntervalIndex([(0, 1], (1, 2], (2, 3]],
276
- closed='right',
277
273
dtype='interval[int64, right]')
278
274
"""
279
275
),
@@ -305,7 +301,6 @@ def from_arrays(
305
301
--------
306
302
>>> pd.IntervalIndex.from_tuples([(0, 1), (1, 2)])
307
303
IntervalIndex([(0, 1], (1, 2]],
308
- closed='right',
309
304
dtype='interval[int64, right]')
310
305
"""
311
306
),
@@ -445,7 +440,6 @@ def is_overlapping(self) -> bool:
445
440
>>> index = pd.IntervalIndex.from_tuples([(0, 2), (1, 3), (4, 5)])
446
441
>>> index
447
442
IntervalIndex([(0, 2], (1, 3], (4, 5]],
448
- closed='right',
449
443
dtype='interval[int64, right]')
450
444
>>> index.is_overlapping
451
445
True
@@ -455,7 +449,6 @@ def is_overlapping(self) -> bool:
455
449
>>> index = pd.interval_range(0, 3, closed='both')
456
450
>>> index
457
451
IntervalIndex([[0, 1], [1, 2], [2, 3]],
458
- closed='both',
459
452
dtype='interval[int64, both]')
460
453
>>> index.is_overlapping
461
454
True
@@ -465,7 +458,6 @@ def is_overlapping(self) -> bool:
465
458
>>> index = pd.interval_range(0, 3, closed='left')
466
459
>>> index
467
460
IntervalIndex([[0, 1), [1, 2), [2, 3)],
468
- closed='left',
469
461
dtype='interval[int64, left]')
470
462
>>> index.is_overlapping
471
463
False
@@ -777,17 +769,11 @@ def _convert_list_indexer(self, keyarr):
777
769
def _is_comparable_dtype (self , dtype : DtypeObj ) -> bool :
778
770
if not isinstance (dtype , IntervalDtype ):
779
771
return False
772
+ if self .closed != dtype .closed :
773
+ return False
780
774
common_subtype = find_common_type ([self .dtype .subtype , dtype .subtype ])
781
775
return not is_object_dtype (common_subtype )
782
776
783
- def _should_compare (self , other ) -> bool :
784
- other = unpack_nested_dtype (other )
785
- if is_object_dtype (other .dtype ):
786
- return True
787
- if not self ._is_comparable_dtype (other .dtype ):
788
- return False
789
- return other .closed == self .closed
790
-
791
777
# --------------------------------------------------------------------
792
778
793
779
@cache_readonly
@@ -911,7 +897,7 @@ def _format_data(self, name=None):
911
897
return summary + "," + self ._format_space ()
912
898
913
899
def _format_attrs (self ):
914
- attrs = [( "closed" , repr ( self . closed )) ]
900
+ attrs = []
915
901
if self .name is not None :
916
902
attrs .append (("name" , default_pprint (self .name )))
917
903
attrs .append (("dtype" , f"'{ self .dtype } '" ))
@@ -1117,7 +1103,6 @@ def interval_range(
1117
1103
1118
1104
>>> pd.interval_range(start=0, end=5)
1119
1105
IntervalIndex([(0, 1], (1, 2], (2, 3], (3, 4], (4, 5]],
1120
- closed='right',
1121
1106
dtype='interval[int64, right]')
1122
1107
1123
1108
Additionally, datetime-like input is also supported.
@@ -1126,15 +1111,15 @@ def interval_range(
1126
1111
... end=pd.Timestamp('2017-01-04'))
1127
1112
IntervalIndex([(2017-01-01, 2017-01-02], (2017-01-02, 2017-01-03],
1128
1113
(2017-01-03, 2017-01-04]],
1129
- closed='right', dtype='interval[datetime64[ns], right]')
1114
+ dtype='interval[datetime64[ns], right]')
1130
1115
1131
1116
The ``freq`` parameter specifies the frequency between the left and right.
1132
1117
endpoints of the individual intervals within the ``IntervalIndex``. For
1133
1118
numeric ``start`` and ``end``, the frequency must also be numeric.
1134
1119
1135
1120
>>> pd.interval_range(start=0, periods=4, freq=1.5)
1136
1121
IntervalIndex([(0.0, 1.5], (1.5, 3.0], (3.0, 4.5], (4.5, 6.0]],
1137
- closed='right', dtype='interval[float64, right]')
1122
+ dtype='interval[float64, right]')
1138
1123
1139
1124
Similarly, for datetime-like ``start`` and ``end``, the frequency must be
1140
1125
convertible to a DateOffset.
@@ -1143,22 +1128,21 @@ def interval_range(
1143
1128
... periods=3, freq='MS')
1144
1129
IntervalIndex([(2017-01-01, 2017-02-01], (2017-02-01, 2017-03-01],
1145
1130
(2017-03-01, 2017-04-01]],
1146
- closed='right', dtype='interval[datetime64[ns], right]')
1131
+ dtype='interval[datetime64[ns], right]')
1147
1132
1148
1133
Specify ``start``, ``end``, and ``periods``; the frequency is generated
1149
1134
automatically (linearly spaced).
1150
1135
1151
1136
>>> pd.interval_range(start=0, end=6, periods=4)
1152
1137
IntervalIndex([(0.0, 1.5], (1.5, 3.0], (3.0, 4.5], (4.5, 6.0]],
1153
- closed='right',
1154
1138
dtype='interval[float64, right]')
1155
1139
1156
1140
The ``closed`` parameter specifies which endpoints of the individual
1157
1141
intervals within the ``IntervalIndex`` are closed.
1158
1142
1159
1143
>>> pd.interval_range(end=5, periods=4, closed='both')
1160
1144
IntervalIndex([[1, 2], [2, 3], [3, 4], [4, 5]],
1161
- closed='both', dtype='interval[int64, both]')
1145
+ dtype='interval[int64, both]')
1162
1146
"""
1163
1147
start = maybe_box_datetimelike (start )
1164
1148
end = maybe_box_datetimelike (end )
0 commit comments