24
24
25
25
from pandas ._libs import lib
26
26
from pandas ._libs .interval import (
27
- VALID_INCLUSIVE ,
27
+ VALID_CLOSED ,
28
28
Interval ,
29
29
IntervalMixin ,
30
30
intervals_to_interval_bounds ,
131
131
Array-like containing Interval objects from which to build the
132
132
%(klass)s.
133
133
inclusive : {'left', 'right', 'both', 'neither'}, default 'right'
134
- Whether the intervals are inclusive on the left-side, right-side, both or
134
+ Whether the intervals are closed on the left-side, right-side, both or
135
135
neither.
136
136
dtype : dtype or None, default None
137
137
If None, dtype will be inferred.
186
186
_interval_shared_docs ["class" ]
187
187
% {
188
188
"klass" : "IntervalArray" ,
189
- "summary" : "Pandas array for interval data that are inclusive on the same "
190
- "side." ,
189
+ "summary" : "Pandas array for interval data that are closed on the same side." ,
191
190
"versionadded" : "0.24.0" ,
192
191
"name" : "" ,
193
192
"extra_attributes" : "" ,
@@ -256,13 +255,13 @@ def __new__(
256
255
257
256
# might need to convert empty or purely na data
258
257
data = _maybe_convert_platform_interval (data )
259
- left , right , infer_inclusive = intervals_to_interval_bounds (
260
- data , validate_inclusive = inclusive is None
258
+ left , right , infer_closed = intervals_to_interval_bounds (
259
+ data , validate_closed = inclusive is None
261
260
)
262
261
if left .dtype == object :
263
262
left = lib .maybe_convert_objects (left )
264
263
right = lib .maybe_convert_objects (right )
265
- inclusive = inclusive or infer_inclusive
264
+ inclusive = inclusive or infer_closed
266
265
267
266
return cls ._simple_new (
268
267
left ,
@@ -391,7 +390,7 @@ def _from_factorized(
391
390
breaks : array-like (1-dimensional)
392
391
Left and right bounds for each interval.
393
392
inclusive : {'left', 'right', 'both', 'neither'}, default 'right'
394
- Whether the intervals are inclusive on the left-side, right-side, both
393
+ Whether the intervals are closed on the left-side, right-side, both
395
394
or neither.
396
395
copy : bool, default False
397
396
Copy the data.
@@ -457,7 +456,7 @@ def from_breaks(
457
456
right : array-like (1-dimensional)
458
457
Right bounds for each interval.
459
458
inclusive : {'left', 'right', 'both', 'neither'}, default 'right'
460
- Whether the intervals are inclusive on the left-side, right-side, both
459
+ Whether the intervals are closed on the left-side, right-side, both
461
460
or neither.
462
461
copy : bool, default False
463
462
Copy the data.
@@ -544,7 +543,7 @@ def from_arrays(
544
543
data : array-like (1-dimensional)
545
544
Array of tuples.
546
545
inclusive : {'left', 'right', 'both', 'neither'}, default 'right'
547
- Whether the intervals are inclusive on the left-side, right-side, both
546
+ Whether the intervals are closed on the left-side, right-side, both
548
547
or neither.
549
548
copy : bool, default False
550
549
By-default copy the data, this is compat only and ignored.
@@ -631,7 +630,7 @@ def _validate(self):
631
630
* left and right have the same missing values
632
631
* left is always below right
633
632
"""
634
- if self .inclusive not in VALID_INCLUSIVE :
633
+ if self .inclusive not in VALID_CLOSED :
635
634
msg = f"invalid option for 'inclusive': { self .inclusive } "
636
635
raise ValueError (msg )
637
636
if len (self ._left ) != len (self ._right ):
@@ -747,7 +746,7 @@ def _cmp_method(self, other, op):
747
746
# for categorical defer to categories for dtype
748
747
other_dtype = other .categories .dtype
749
748
750
- # extract intervals if we have interval categories with matching inclusive
749
+ # extract intervals if we have interval categories with matching closed
751
750
if is_interval_dtype (other_dtype ):
752
751
if self .inclusive != other .categories .inclusive :
753
752
return invalid_comparison (self , other , op )
@@ -756,7 +755,7 @@ def _cmp_method(self, other, op):
756
755
other .codes , allow_fill = True , fill_value = other .categories ._na_value
757
756
)
758
757
759
- # interval-like -> need same inclusive and matching endpoints
758
+ # interval-like -> need same closed and matching endpoints
760
759
if is_interval_dtype (other_dtype ):
761
760
if self .inclusive != other .inclusive :
762
761
return invalid_comparison (self , other , op )
@@ -996,7 +995,7 @@ def _concat_same_type(
996
995
"""
997
996
inclusive_set = {interval .inclusive for interval in to_concat }
998
997
if len (inclusive_set ) != 1 :
999
- raise ValueError ("Intervals must all be inclusive on the same side." )
998
+ raise ValueError ("Intervals must all be closed on the same side." )
1000
999
inclusive = inclusive_set .pop ()
1001
1000
1002
1001
left = np .concatenate ([interval .left for interval in to_concat ])
@@ -1122,7 +1121,7 @@ def _validate_listlike(self, value):
1122
1121
# list-like of intervals
1123
1122
try :
1124
1123
array = IntervalArray (value )
1125
- self ._check_inclusive_matches (array , name = "value" )
1124
+ self ._check_closed_matches (array , name = "value" )
1126
1125
value_left , value_right = array .left , array .right
1127
1126
except TypeError as err :
1128
1127
# wrong type: not interval or NA
@@ -1142,7 +1141,7 @@ def _validate_listlike(self, value):
1142
1141
1143
1142
def _validate_scalar (self , value ):
1144
1143
if isinstance (value , Interval ):
1145
- self ._check_inclusive_matches (value , name = "value" )
1144
+ self ._check_closed_matches (value , name = "value" )
1146
1145
left , right = value .left , value .right
1147
1146
# TODO: check subdtype match like _validate_setitem_value?
1148
1147
elif is_valid_na_for_dtype (value , self .left .dtype ):
@@ -1168,7 +1167,7 @@ def _validate_setitem_value(self, value):
1168
1167
1169
1168
elif isinstance (value , Interval ):
1170
1169
# scalar
1171
- self ._check_inclusive_matches (value , name = "value" )
1170
+ self ._check_closed_matches (value , name = "value" )
1172
1171
value_left , value_right = value .left , value .right
1173
1172
self .left ._validate_fill_value (value_left )
1174
1173
self .left ._validate_fill_value (value_right )
@@ -1351,7 +1350,7 @@ def overlaps(self, other):
1351
1350
msg = f"`other` must be Interval-like, got { type (other ).__name__ } "
1352
1351
raise TypeError (msg )
1353
1352
1354
- # equality is okay if both endpoints are inclusive (overlap at a point)
1353
+ # equality is okay if both endpoints are closed (overlap at a point)
1355
1354
op1 = le if (self .closed_left and other .closed_right ) else lt
1356
1355
op2 = le if (other .closed_left and self .closed_right ) else lt
1357
1356
@@ -1365,9 +1364,8 @@ def overlaps(self, other):
1365
1364
@property
1366
1365
def inclusive (self ) -> IntervalInclusiveType :
1367
1366
"""
1368
- String describing the inclusive side the intervals.
1369
-
1370
- Either ``left``, ``right``, ``both`` or ``neither``.
1367
+ Whether the intervals are closed on the left-side, right-side, both or
1368
+ neither.
1371
1369
"""
1372
1370
return self .dtype .inclusive
1373
1371
@@ -1481,7 +1479,7 @@ def set_closed(
1481
1479
def set_inclusive (
1482
1480
self : IntervalArrayT , inclusive : IntervalInclusiveType
1483
1481
) -> IntervalArrayT :
1484
- if inclusive not in VALID_INCLUSIVE :
1482
+ if inclusive not in VALID_CLOSED :
1485
1483
msg = f"invalid option for 'inclusive': { inclusive } "
1486
1484
raise ValueError (msg )
1487
1485
0 commit comments