Skip to content

Commit 102b3ca

Browse files
authored
CLN: Rename private variables to inclusive (pandas-dev#47655)
* CLN: Rename private variables from closed to inclusive * Rename variables in dtypes too * Fix tests
1 parent 9b63034 commit 102b3ca

File tree

8 files changed

+67
-64
lines changed

8 files changed

+67
-64
lines changed

pandas/_libs/interval.pyi

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ from pandas._typing import (
1717
Timestamp,
1818
)
1919

20-
VALID_CLOSED: frozenset[str]
20+
VALID_INCLUSIVE: frozenset[str]
2121

2222
_OrderableScalarT = TypeVar("_OrderableScalarT", int, float)
2323
_OrderableTimesT = TypeVar("_OrderableTimesT", Timestamp, Timedelta)
@@ -52,7 +52,9 @@ class IntervalMixin:
5252
def open_right(self) -> bool: ...
5353
@property
5454
def is_empty(self) -> bool: ...
55-
def _check_closed_matches(self, other: IntervalMixin, name: str = ...) -> None: ...
55+
def _check_inclusive_matches(
56+
self, other: IntervalMixin, name: str = ...
57+
) -> None: ...
5658

5759
def _warning_interval(
5860
inclusive, closed
@@ -150,7 +152,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
150152
def overlaps(self: Interval[_OrderableT], other: Interval[_OrderableT]) -> bool: ...
151153

152154
def intervals_to_interval_bounds(
153-
intervals: np.ndarray, validate_closed: bool = ...
155+
intervals: np.ndarray, validate_inclusive: bool = ...
154156
) -> tuple[np.ndarray, np.ndarray, IntervalInclusiveType]: ...
155157

156158
class IntervalTree(IntervalMixin):

pandas/_libs/interval.pyx

+25-25
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ from pandas._libs.tslibs.util cimport (
5656
is_timedelta64_object,
5757
)
5858

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

6161

6262
cdef class IntervalMixin:
@@ -85,7 +85,7 @@ cdef class IntervalMixin:
8585
Returns
8686
-------
8787
bool
88-
True if the Interval is closed on the left-side.
88+
True if the Interval is closed on the right-side.
8989
"""
9090
return self.inclusive in ('right', 'both')
9191

@@ -99,7 +99,7 @@ cdef class IntervalMixin:
9999
Returns
100100
-------
101101
bool
102-
True if the Interval is closed on the left-side.
102+
True if the Interval is not closed on the left-side.
103103
"""
104104
return not self.closed_left
105105

@@ -113,7 +113,7 @@ cdef class IntervalMixin:
113113
Returns
114114
-------
115115
bool
116-
True if the Interval is closed on the left-side.
116+
True if the Interval is not closed on the right-side.
117117
"""
118118
return not self.closed_right
119119

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

191-
def _check_closed_matches(self, other, name='other'):
191+
def _check_inclusive_matches(self, other, name='other'):
192192
"""
193193
Check if the inclusive attribute of `other` matches.
194194
@@ -203,7 +203,7 @@ cdef class IntervalMixin:
203203
Raises
204204
------
205205
ValueError
206-
When `other` is not closed exactly the same as self.
206+
When `other` is not inclusive exactly the same as self.
207207
"""
208208
if self.inclusive != other.inclusive:
209209
raise ValueError(f"'{name}.inclusive' is {repr(other.inclusive)}, "
@@ -259,14 +259,14 @@ cdef class Interval(IntervalMixin):
259259
.. deprecated:: 1.5.0
260260
261261
inclusive : {'both', 'neither', 'left', 'right'}, default 'both'
262-
Whether the interval is closed on the left-side, right-side, both or
262+
Whether the interval is inclusive on the left-side, right-side, both or
263263
neither. See the Notes for more detailed explanation.
264264
265265
.. versionadded:: 1.5.0
266266
267267
See Also
268268
--------
269-
IntervalIndex : An Index of Interval objects that are all closed on the
269+
IntervalIndex : An Index of Interval objects that are all inclusive on the
270270
same side.
271271
cut : Convert continuous data into discrete bins (Categorical
272272
of Interval objects).
@@ -279,13 +279,13 @@ cdef class Interval(IntervalMixin):
279279
The parameters `left` and `right` must be from the same type, you must be
280280
able to compare them and they must satisfy ``left <= right``.
281281
282-
A closed interval (in mathematics denoted by square brackets) contains
283-
its endpoints, i.e. the closed interval ``[0, 5]`` is characterized by the
282+
A inclusive interval (in mathematics denoted by square brackets) contains
283+
its endpoints, i.e. the inclusive interval ``[0, 5]`` is characterized by the
284284
conditions ``0 <= x <= 5``. This is what ``inclusive='both'`` stands for.
285285
An open interval (in mathematics denoted by parentheses) does not contain
286286
its endpoints, i.e. the open interval ``(0, 5)`` is characterized by the
287287
conditions ``0 < x < 5``. This is what ``inclusive='neither'`` stands for.
288-
Intervals can also be half-open or half-closed, i.e. ``[0, 5)`` is
288+
Intervals can also be half-open or half-inclusive, i.e. ``[0, 5)`` is
289289
described by ``0 <= x < 5`` (``inclusive='left'``) and ``(0, 5]`` is
290290
described by ``0 < x <= 5`` (``inclusive='right'``).
291291
@@ -352,7 +352,7 @@ cdef class Interval(IntervalMixin):
352352

353353
cdef readonly str inclusive
354354
"""
355-
Whether the interval is closed on the left-side, right-side, both or
355+
Whether the interval is inclusive on the left-side, right-side, both or
356356
neither.
357357
"""
358358

@@ -368,7 +368,7 @@ cdef class Interval(IntervalMixin):
368368
if inclusive is None:
369369
inclusive = "right"
370370

371-
if inclusive not in VALID_CLOSED:
371+
if inclusive not in VALID_INCLUSIVE:
372372
raise ValueError(f"invalid option for 'inclusive': {inclusive}")
373373
if not left <= right:
374374
raise ValueError("left side of interval must be <= right side")
@@ -522,7 +522,7 @@ cdef class Interval(IntervalMixin):
522522
"""
523523
Check whether two Interval objects overlap.
524524
525-
Two intervals overlap if they share a common point, including closed
525+
Two intervals overlap if they share a common point, including inclusive
526526
endpoints. Intervals that only have an open endpoint in common do not
527527
overlap.
528528
@@ -551,7 +551,7 @@ cdef class Interval(IntervalMixin):
551551
>>> i1.overlaps(i3)
552552
False
553553
554-
Intervals that share closed endpoints overlap:
554+
Intervals that share inclusive endpoints overlap:
555555
556556
>>> i4 = pd.Interval(0, 1, inclusive='both')
557557
>>> i5 = pd.Interval(1, 2, inclusive='both')
@@ -568,7 +568,7 @@ cdef class Interval(IntervalMixin):
568568
raise TypeError("`other` must be an Interval, "
569569
f"got {type(other).__name__}")
570570

571-
# equality is okay if both endpoints are closed (overlap at a point)
571+
# equality is okay if both endpoints are inclusive (overlap at a point)
572572
op1 = le if (self.closed_left and other.closed_right) else lt
573573
op2 = le if (other.closed_left and self.closed_right) else lt
574574

@@ -580,16 +580,16 @@ cdef class Interval(IntervalMixin):
580580

581581
@cython.wraparound(False)
582582
@cython.boundscheck(False)
583-
def intervals_to_interval_bounds(ndarray intervals, bint validate_closed=True):
583+
def intervals_to_interval_bounds(ndarray intervals, bint validate_inclusive=True):
584584
"""
585585
Parameters
586586
----------
587587
intervals : ndarray
588588
Object array of Intervals / nulls.
589589
590-
validate_closed: bool, default True
591-
Boolean indicating if all intervals must be closed on the same side.
592-
Mismatching closed will raise if True, else return None for closed.
590+
validate_inclusive: bool, default True
591+
Boolean indicating if all intervals must be inclusive on the same side.
592+
Mismatching inclusive will raise if True, else return None for inclusive.
593593
594594
Returns
595595
-------
@@ -602,7 +602,7 @@ def intervals_to_interval_bounds(ndarray intervals, bint validate_closed=True):
602602
object inclusive = None, interval
603603
Py_ssize_t i, n = len(intervals)
604604
ndarray left, right
605-
bint seen_closed = False
605+
bint seen_inclusive = False
606606

607607
left = np.empty(n, dtype=intervals.dtype)
608608
right = np.empty(n, dtype=intervals.dtype)
@@ -620,13 +620,13 @@ def intervals_to_interval_bounds(ndarray intervals, bint validate_closed=True):
620620

621621
left[i] = interval.left
622622
right[i] = interval.right
623-
if not seen_closed:
624-
seen_closed = True
623+
if not seen_inclusive:
624+
seen_inclusive = True
625625
inclusive = interval.inclusive
626626
elif inclusive != interval.inclusive:
627627
inclusive = None
628-
if validate_closed:
629-
raise ValueError("intervals must all be closed on the same side")
628+
if validate_inclusive:
629+
raise ValueError("intervals must all be inclusive on the same side")
630630

631631
return left, right, inclusive
632632

pandas/core/arrays/arrow/_arrow_utils.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from pandas.util._decorators import deprecate_kwarg
1212
from pandas.util._exceptions import find_stack_level
1313

14-
from pandas.core.arrays.interval import VALID_CLOSED
14+
from pandas.core.arrays.interval import VALID_INCLUSIVE
1515

1616

1717
def fallback_performancewarning(version: str | None = None) -> None:
@@ -111,8 +111,8 @@ class ArrowIntervalType(pyarrow.ExtensionType):
111111
def __init__(self, subtype, inclusive: IntervalInclusiveType) -> None:
112112
# attributes need to be set first before calling
113113
# super init (as that calls serialize)
114-
assert inclusive in VALID_CLOSED
115-
self._closed: IntervalInclusiveType = inclusive
114+
assert inclusive in VALID_INCLUSIVE
115+
self._inclusive: IntervalInclusiveType = inclusive
116116
if not isinstance(subtype, pyarrow.DataType):
117117
subtype = pyarrow.type_for_alias(str(subtype))
118118
self._subtype = subtype
@@ -126,7 +126,7 @@ def subtype(self):
126126

127127
@property
128128
def inclusive(self) -> IntervalInclusiveType:
129-
return self._closed
129+
return self._inclusive
130130

131131
@property
132132
def closed(self) -> IntervalInclusiveType:
@@ -135,7 +135,7 @@ def closed(self) -> IntervalInclusiveType:
135135
FutureWarning,
136136
stacklevel=find_stack_level(),
137137
)
138-
return self._closed
138+
return self._inclusive
139139

140140
def __arrow_ext_serialize__(self) -> bytes:
141141
metadata = {"subtype": str(self.subtype), "inclusive": self.inclusive}

0 commit comments

Comments
 (0)