Skip to content

Commit 0b7c648

Browse files
committed
Revert "CLN: Rename private variables to inclusive (pandas-dev#47655)"
This reverts commit 102b3ca.
1 parent 0397ea3 commit 0b7c648

File tree

8 files changed

+63
-68
lines changed

8 files changed

+63
-68
lines changed

pandas/_libs/interval.pyi

+3-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ from pandas._typing import (
1515
Timestamp,
1616
)
1717

18-
VALID_INCLUSIVE: frozenset[str]
18+
VALID_CLOSED: frozenset[str]
1919

2020
_OrderableScalarT = TypeVar("_OrderableScalarT", int, float)
2121
_OrderableTimesT = TypeVar("_OrderableTimesT", Timestamp, Timedelta)
@@ -50,9 +50,7 @@ class IntervalMixin:
5050
def open_right(self) -> bool: ...
5151
@property
5252
def is_empty(self) -> bool: ...
53-
def _check_inclusive_matches(
54-
self, other: IntervalMixin, name: str = ...
55-
) -> None: ...
53+
def _check_closed_matches(self, other: IntervalMixin, name: str = ...) -> None: ...
5654

5755
def _warning_interval(
5856
inclusive, closed
@@ -157,7 +155,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
157155
def overlaps(self: Interval[_OrderableT], other: Interval[_OrderableT]) -> bool: ...
158156

159157
def intervals_to_interval_bounds(
160-
intervals: np.ndarray, validate_inclusive: bool = ...
158+
intervals: np.ndarray, validate_closed: bool = ...
161159
) -> tuple[np.ndarray, np.ndarray, IntervalInclusiveType]: ...
162160

163161
class IntervalTree(IntervalMixin):

pandas/_libs/interval.pyx

+26-27
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ from pandas._libs.tslibs.util cimport (
5858
is_timedelta64_object,
5959
)
6060

61-
VALID_INCLUSIVE = frozenset(['both', 'neither', 'left', 'right'])
61+
VALID_CLOSED = frozenset(['both', 'neither', 'left', 'right'])
6262

6363

6464
cdef class IntervalMixin:
@@ -87,7 +87,7 @@ cdef class IntervalMixin:
8787
Returns
8888
-------
8989
bool
90-
True if the Interval is closed on the right-side.
90+
True if the Interval is closed on the left-side.
9191
"""
9292
return self.inclusive in ('right', 'both')
9393

@@ -101,7 +101,7 @@ cdef class IntervalMixin:
101101
Returns
102102
-------
103103
bool
104-
True if the Interval is not closed on the left-side.
104+
True if the Interval is closed on the left-side.
105105
"""
106106
return not self.closed_left
107107

@@ -115,7 +115,7 @@ cdef class IntervalMixin:
115115
Returns
116116
-------
117117
bool
118-
True if the Interval is not closed on the right-side.
118+
True if the Interval is closed on the left-side.
119119
"""
120120
return not self.closed_right
121121

@@ -190,7 +190,7 @@ cdef class IntervalMixin:
190190
"""
191191
return (self.right == self.left) & (self.inclusive != 'both')
192192

193-
def _check_inclusive_matches(self, other, name='other'):
193+
def _check_closed_matches(self, other, name='other'):
194194
"""
195195
Check if the inclusive attribute of `other` matches.
196196
@@ -205,7 +205,7 @@ cdef class IntervalMixin:
205205
Raises
206206
------
207207
ValueError
208-
When `other` is not inclusive exactly the same as self.
208+
When `other` is not closed exactly the same as self.
209209
"""
210210
if self.inclusive != other.inclusive:
211211
raise ValueError(f"'{name}.inclusive' is {repr(other.inclusive)}, "
@@ -261,14 +261,14 @@ cdef class Interval(IntervalMixin):
261261
.. deprecated:: 1.5.0
262262
263263
inclusive : {'both', 'neither', 'left', 'right'}, default 'both'
264-
Whether the interval is inclusive on the left-side, right-side, both or
264+
Whether the interval is closed on the left-side, right-side, both or
265265
neither. See the Notes for more detailed explanation.
266266
267267
.. versionadded:: 1.5.0
268268
269269
See Also
270270
--------
271-
IntervalIndex : An Index of Interval objects that are all inclusive on the
271+
IntervalIndex : An Index of Interval objects that are all closed on the
272272
same side.
273273
cut : Convert continuous data into discrete bins (Categorical
274274
of Interval objects).
@@ -281,13 +281,13 @@ cdef class Interval(IntervalMixin):
281281
The parameters `left` and `right` must be from the same type, you must be
282282
able to compare them and they must satisfy ``left <= right``.
283283
284-
A inclusive interval (in mathematics denoted by square brackets) contains
285-
its endpoints, i.e. the inclusive interval ``[0, 5]`` is characterized by the
284+
A closed interval (in mathematics denoted by square brackets) contains
285+
its endpoints, i.e. the closed interval ``[0, 5]`` is characterized by the
286286
conditions ``0 <= x <= 5``. This is what ``inclusive='both'`` stands for.
287287
An open interval (in mathematics denoted by parentheses) does not contain
288288
its endpoints, i.e. the open interval ``(0, 5)`` is characterized by the
289289
conditions ``0 < x < 5``. This is what ``inclusive='neither'`` stands for.
290-
Intervals can also be half-open or half-inclusive, i.e. ``[0, 5)`` is
290+
Intervals can also be half-open or half-closed, i.e. ``[0, 5)`` is
291291
described by ``0 <= x < 5`` (``inclusive='left'``) and ``(0, 5]`` is
292292
described by ``0 < x <= 5`` (``inclusive='right'``).
293293
@@ -356,9 +356,8 @@ cdef class Interval(IntervalMixin):
356356

357357
cdef readonly str inclusive
358358
"""
359-
String describing the inclusive side the intervals.
360-
361-
Either ``left``, ``right``, ``both`` or ``neither``.
359+
Whether the interval is closed on the left-side, right-side, both or
360+
neither.
362361
"""
363362

364363
def __init__(self, left, right, inclusive: str | None = None, closed: None | lib.NoDefault = lib.no_default):
@@ -373,7 +372,7 @@ cdef class Interval(IntervalMixin):
373372
if inclusive is None:
374373
inclusive = "right"
375374

376-
if inclusive not in VALID_INCLUSIVE:
375+
if inclusive not in VALID_CLOSED:
377376
raise ValueError(f"invalid option for 'inclusive': {inclusive}")
378377
if not left <= right:
379378
raise ValueError("left side of interval must be <= right side")
@@ -538,7 +537,7 @@ cdef class Interval(IntervalMixin):
538537
"""
539538
Check whether two Interval objects overlap.
540539
541-
Two intervals overlap if they share a common point, including inclusive
540+
Two intervals overlap if they share a common point, including closed
542541
endpoints. Intervals that only have an open endpoint in common do not
543542
overlap.
544543
@@ -567,7 +566,7 @@ cdef class Interval(IntervalMixin):
567566
>>> i1.overlaps(i3)
568567
False
569568
570-
Intervals that share inclusive endpoints overlap:
569+
Intervals that share closed endpoints overlap:
571570
572571
>>> i4 = pd.Interval(0, 1, inclusive='both')
573572
>>> i5 = pd.Interval(1, 2, inclusive='both')
@@ -584,7 +583,7 @@ cdef class Interval(IntervalMixin):
584583
raise TypeError("`other` must be an Interval, "
585584
f"got {type(other).__name__}")
586585

587-
# equality is okay if both endpoints are inclusive (overlap at a point)
586+
# equality is okay if both endpoints are closed (overlap at a point)
588587
op1 = le if (self.closed_left and other.closed_right) else lt
589588
op2 = le if (other.closed_left and self.closed_right) else lt
590589

@@ -596,16 +595,16 @@ cdef class Interval(IntervalMixin):
596595

597596
@cython.wraparound(False)
598597
@cython.boundscheck(False)
599-
def intervals_to_interval_bounds(ndarray intervals, bint validate_inclusive=True):
598+
def intervals_to_interval_bounds(ndarray intervals, bint validate_closed=True):
600599
"""
601600
Parameters
602601
----------
603602
intervals : ndarray
604603
Object array of Intervals / nulls.
605604
606-
validate_inclusive: bool, default True
607-
Boolean indicating if all intervals must be inclusive on the same side.
608-
Mismatching inclusive will raise if True, else return None for inclusive.
605+
validate_closed: bool, default True
606+
Boolean indicating if all intervals must be closed on the same side.
607+
Mismatching closed will raise if True, else return None for closed.
609608
610609
Returns
611610
-------
@@ -618,7 +617,7 @@ def intervals_to_interval_bounds(ndarray intervals, bint validate_inclusive=True
618617
object inclusive = None, interval
619618
Py_ssize_t i, n = len(intervals)
620619
ndarray left, right
621-
bint seen_inclusive = False
620+
bint seen_closed = False
622621

623622
left = np.empty(n, dtype=intervals.dtype)
624623
right = np.empty(n, dtype=intervals.dtype)
@@ -636,13 +635,13 @@ def intervals_to_interval_bounds(ndarray intervals, bint validate_inclusive=True
636635

637636
left[i] = interval.left
638637
right[i] = interval.right
639-
if not seen_inclusive:
640-
seen_inclusive = True
638+
if not seen_closed:
639+
seen_closed = True
641640
inclusive = interval.inclusive
642641
elif inclusive != interval.inclusive:
643642
inclusive = None
644-
if validate_inclusive:
645-
raise ValueError("intervals must all be inclusive on the same side")
643+
if validate_closed:
644+
raise ValueError("intervals must all be closed on the same side")
646645

647646
return left, right, inclusive
648647

pandas/core/arrays/arrow/extension_types.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pandas.util._decorators import deprecate_kwarg
1010
from pandas.util._exceptions import find_stack_level
1111

12-
from pandas.core.arrays.interval import VALID_INCLUSIVE
12+
from pandas.core.arrays.interval import VALID_CLOSED
1313

1414

1515
class ArrowPeriodType(pyarrow.ExtensionType):
@@ -57,7 +57,7 @@ class ArrowIntervalType(pyarrow.ExtensionType):
5757
def __init__(self, subtype, inclusive: IntervalInclusiveType) -> None:
5858
# attributes need to be set first before calling
5959
# super init (as that calls serialize)
60-
assert inclusive in VALID_INCLUSIVE
60+
assert inclusive in VALID_CLOSED
6161
self._inclusive: IntervalInclusiveType = inclusive
6262
if not isinstance(subtype, pyarrow.DataType):
6363
subtype = pyarrow.type_for_alias(str(subtype))

pandas/core/arrays/interval.py

+20-22
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
from pandas._libs import lib
2626
from pandas._libs.interval import (
27-
VALID_INCLUSIVE,
27+
VALID_CLOSED,
2828
Interval,
2929
IntervalMixin,
3030
intervals_to_interval_bounds,
@@ -131,7 +131,7 @@
131131
Array-like containing Interval objects from which to build the
132132
%(klass)s.
133133
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
135135
neither.
136136
dtype : dtype or None, default None
137137
If None, dtype will be inferred.
@@ -186,8 +186,7 @@
186186
_interval_shared_docs["class"]
187187
% {
188188
"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.",
191190
"versionadded": "0.24.0",
192191
"name": "",
193192
"extra_attributes": "",
@@ -256,13 +255,13 @@ def __new__(
256255

257256
# might need to convert empty or purely na data
258257
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
261260
)
262261
if left.dtype == object:
263262
left = lib.maybe_convert_objects(left)
264263
right = lib.maybe_convert_objects(right)
265-
inclusive = inclusive or infer_inclusive
264+
inclusive = inclusive or infer_closed
266265

267266
return cls._simple_new(
268267
left,
@@ -391,7 +390,7 @@ def _from_factorized(
391390
breaks : array-like (1-dimensional)
392391
Left and right bounds for each interval.
393392
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
395394
or neither.
396395
copy : bool, default False
397396
Copy the data.
@@ -457,7 +456,7 @@ def from_breaks(
457456
right : array-like (1-dimensional)
458457
Right bounds for each interval.
459458
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
461460
or neither.
462461
copy : bool, default False
463462
Copy the data.
@@ -544,7 +543,7 @@ def from_arrays(
544543
data : array-like (1-dimensional)
545544
Array of tuples.
546545
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
548547
or neither.
549548
copy : bool, default False
550549
By-default copy the data, this is compat only and ignored.
@@ -631,7 +630,7 @@ def _validate(self):
631630
* left and right have the same missing values
632631
* left is always below right
633632
"""
634-
if self.inclusive not in VALID_INCLUSIVE:
633+
if self.inclusive not in VALID_CLOSED:
635634
msg = f"invalid option for 'inclusive': {self.inclusive}"
636635
raise ValueError(msg)
637636
if len(self._left) != len(self._right):
@@ -747,7 +746,7 @@ def _cmp_method(self, other, op):
747746
# for categorical defer to categories for dtype
748747
other_dtype = other.categories.dtype
749748

750-
# extract intervals if we have interval categories with matching inclusive
749+
# extract intervals if we have interval categories with matching closed
751750
if is_interval_dtype(other_dtype):
752751
if self.inclusive != other.categories.inclusive:
753752
return invalid_comparison(self, other, op)
@@ -756,7 +755,7 @@ def _cmp_method(self, other, op):
756755
other.codes, allow_fill=True, fill_value=other.categories._na_value
757756
)
758757

759-
# interval-like -> need same inclusive and matching endpoints
758+
# interval-like -> need same closed and matching endpoints
760759
if is_interval_dtype(other_dtype):
761760
if self.inclusive != other.inclusive:
762761
return invalid_comparison(self, other, op)
@@ -996,7 +995,7 @@ def _concat_same_type(
996995
"""
997996
inclusive_set = {interval.inclusive for interval in to_concat}
998997
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.")
1000999
inclusive = inclusive_set.pop()
10011000

10021001
left = np.concatenate([interval.left for interval in to_concat])
@@ -1122,7 +1121,7 @@ def _validate_listlike(self, value):
11221121
# list-like of intervals
11231122
try:
11241123
array = IntervalArray(value)
1125-
self._check_inclusive_matches(array, name="value")
1124+
self._check_closed_matches(array, name="value")
11261125
value_left, value_right = array.left, array.right
11271126
except TypeError as err:
11281127
# wrong type: not interval or NA
@@ -1142,7 +1141,7 @@ def _validate_listlike(self, value):
11421141

11431142
def _validate_scalar(self, value):
11441143
if isinstance(value, Interval):
1145-
self._check_inclusive_matches(value, name="value")
1144+
self._check_closed_matches(value, name="value")
11461145
left, right = value.left, value.right
11471146
# TODO: check subdtype match like _validate_setitem_value?
11481147
elif is_valid_na_for_dtype(value, self.left.dtype):
@@ -1168,7 +1167,7 @@ def _validate_setitem_value(self, value):
11681167

11691168
elif isinstance(value, Interval):
11701169
# scalar
1171-
self._check_inclusive_matches(value, name="value")
1170+
self._check_closed_matches(value, name="value")
11721171
value_left, value_right = value.left, value.right
11731172
self.left._validate_fill_value(value_left)
11741173
self.left._validate_fill_value(value_right)
@@ -1351,7 +1350,7 @@ def overlaps(self, other):
13511350
msg = f"`other` must be Interval-like, got {type(other).__name__}"
13521351
raise TypeError(msg)
13531352

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)
13551354
op1 = le if (self.closed_left and other.closed_right) else lt
13561355
op2 = le if (other.closed_left and self.closed_right) else lt
13571356

@@ -1365,9 +1364,8 @@ def overlaps(self, other):
13651364
@property
13661365
def inclusive(self) -> IntervalInclusiveType:
13671366
"""
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.
13711369
"""
13721370
return self.dtype.inclusive
13731371

@@ -1481,7 +1479,7 @@ def set_closed(
14811479
def set_inclusive(
14821480
self: IntervalArrayT, inclusive: IntervalInclusiveType
14831481
) -> IntervalArrayT:
1484-
if inclusive not in VALID_INCLUSIVE:
1482+
if inclusive not in VALID_CLOSED:
14851483
msg = f"invalid option for 'inclusive': {inclusive}"
14861484
raise ValueError(msg)
14871485

0 commit comments

Comments
 (0)