Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLN: Rename private variables to inclusive #47655

Merged
merged 4 commits into from
Jul 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions pandas/_libs/interval.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ from pandas._typing import (
Timestamp,
)

VALID_CLOSED: frozenset[str]
VALID_INCLUSIVE: frozenset[str]

_OrderableScalarT = TypeVar("_OrderableScalarT", int, float)
_OrderableTimesT = TypeVar("_OrderableTimesT", Timestamp, Timedelta)
Expand Down Expand Up @@ -52,7 +52,9 @@ class IntervalMixin:
def open_right(self) -> bool: ...
@property
def is_empty(self) -> bool: ...
def _check_closed_matches(self, other: IntervalMixin, name: str = ...) -> None: ...
def _check_inclusive_matches(
self, other: IntervalMixin, name: str = ...
) -> None: ...

def _warning_interval(
inclusive, closed
Expand Down Expand Up @@ -150,7 +152,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
def overlaps(self: Interval[_OrderableT], other: Interval[_OrderableT]) -> bool: ...

def intervals_to_interval_bounds(
intervals: np.ndarray, validate_closed: bool = ...
intervals: np.ndarray, validate_inclusive: bool = ...
) -> tuple[np.ndarray, np.ndarray, IntervalInclusiveType]: ...

class IntervalTree(IntervalMixin):
Expand Down
50 changes: 25 additions & 25 deletions pandas/_libs/interval.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ from pandas._libs.tslibs.util cimport (
is_timedelta64_object,
)

VALID_CLOSED = frozenset(['both', 'neither', 'left', 'right'])
VALID_INCLUSIVE = frozenset(['both', 'neither', 'left', 'right'])


cdef class IntervalMixin:
Expand Down Expand Up @@ -85,7 +85,7 @@ cdef class IntervalMixin:
Returns
-------
bool
True if the Interval is closed on the left-side.
True if the Interval is closed on the right-side.
"""
return self.inclusive in ('right', 'both')

Expand All @@ -99,7 +99,7 @@ cdef class IntervalMixin:
Returns
-------
bool
True if the Interval is closed on the left-side.
True if the Interval is not closed on the left-side.
"""
return not self.closed_left

Expand All @@ -113,7 +113,7 @@ cdef class IntervalMixin:
Returns
-------
bool
True if the Interval is closed on the left-side.
True if the Interval is not closed on the right-side.
"""
return not self.closed_right

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

def _check_closed_matches(self, other, name='other'):
def _check_inclusive_matches(self, other, name='other'):
"""
Check if the inclusive attribute of `other` matches.

Expand All @@ -203,7 +203,7 @@ cdef class IntervalMixin:
Raises
------
ValueError
When `other` is not closed exactly the same as self.
When `other` is not inclusive exactly the same as self.
"""
if self.inclusive != other.inclusive:
raise ValueError(f"'{name}.inclusive' is {repr(other.inclusive)}, "
Expand Down Expand Up @@ -259,14 +259,14 @@ cdef class Interval(IntervalMixin):
.. deprecated:: 1.5.0

inclusive : {'both', 'neither', 'left', 'right'}, default 'both'
Whether the interval is closed on the left-side, right-side, both or
Whether the interval is inclusive on the left-side, right-side, both or
neither. See the Notes for more detailed explanation.

.. versionadded:: 1.5.0

See Also
--------
IntervalIndex : An Index of Interval objects that are all closed on the
IntervalIndex : An Index of Interval objects that are all inclusive on the
same side.
cut : Convert continuous data into discrete bins (Categorical
of Interval objects).
Expand All @@ -279,13 +279,13 @@ cdef class Interval(IntervalMixin):
The parameters `left` and `right` must be from the same type, you must be
able to compare them and they must satisfy ``left <= right``.

A closed interval (in mathematics denoted by square brackets) contains
its endpoints, i.e. the closed interval ``[0, 5]`` is characterized by the
A inclusive interval (in mathematics denoted by square brackets) contains
its endpoints, i.e. the inclusive interval ``[0, 5]`` is characterized by the
conditions ``0 <= x <= 5``. This is what ``inclusive='both'`` stands for.
An open interval (in mathematics denoted by parentheses) does not contain
its endpoints, i.e. the open interval ``(0, 5)`` is characterized by the
conditions ``0 < x < 5``. This is what ``inclusive='neither'`` stands for.
Intervals can also be half-open or half-closed, i.e. ``[0, 5)`` is
Intervals can also be half-open or half-inclusive, i.e. ``[0, 5)`` is
described by ``0 <= x < 5`` (``inclusive='left'``) and ``(0, 5]`` is
described by ``0 < x <= 5`` (``inclusive='right'``).

Expand Down Expand Up @@ -352,7 +352,7 @@ cdef class Interval(IntervalMixin):

cdef readonly str inclusive
"""
Whether the interval is closed on the left-side, right-side, both or
Whether the interval is inclusive on the left-side, right-side, both or
neither.
"""

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

if inclusive not in VALID_CLOSED:
if inclusive not in VALID_INCLUSIVE:
raise ValueError(f"invalid option for 'inclusive': {inclusive}")
if not left <= right:
raise ValueError("left side of interval must be <= right side")
Expand Down Expand Up @@ -522,7 +522,7 @@ cdef class Interval(IntervalMixin):
"""
Check whether two Interval objects overlap.

Two intervals overlap if they share a common point, including closed
Two intervals overlap if they share a common point, including inclusive
endpoints. Intervals that only have an open endpoint in common do not
overlap.

Expand Down Expand Up @@ -551,7 +551,7 @@ cdef class Interval(IntervalMixin):
>>> i1.overlaps(i3)
False

Intervals that share closed endpoints overlap:
Intervals that share inclusive endpoints overlap:

>>> i4 = pd.Interval(0, 1, inclusive='both')
>>> i5 = pd.Interval(1, 2, inclusive='both')
Expand All @@ -568,7 +568,7 @@ cdef class Interval(IntervalMixin):
raise TypeError("`other` must be an Interval, "
f"got {type(other).__name__}")

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

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

@cython.wraparound(False)
@cython.boundscheck(False)
def intervals_to_interval_bounds(ndarray intervals, bint validate_closed=True):
def intervals_to_interval_bounds(ndarray intervals, bint validate_inclusive=True):
"""
Parameters
----------
intervals : ndarray
Object array of Intervals / nulls.

validate_closed: bool, default True
Boolean indicating if all intervals must be closed on the same side.
Mismatching closed will raise if True, else return None for closed.
validate_inclusive: bool, default True
Boolean indicating if all intervals must be inclusive on the same side.
Mismatching inclusive will raise if True, else return None for inclusive.

Returns
-------
Expand All @@ -602,7 +602,7 @@ def intervals_to_interval_bounds(ndarray intervals, bint validate_closed=True):
object inclusive = None, interval
Py_ssize_t i, n = len(intervals)
ndarray left, right
bint seen_closed = False
bint seen_inclusive = False

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

left[i] = interval.left
right[i] = interval.right
if not seen_closed:
seen_closed = True
if not seen_inclusive:
seen_inclusive = True
inclusive = interval.inclusive
elif inclusive != interval.inclusive:
inclusive = None
if validate_closed:
raise ValueError("intervals must all be closed on the same side")
if validate_inclusive:
raise ValueError("intervals must all be inclusive on the same side")

return left, right, inclusive

Expand Down
10 changes: 5 additions & 5 deletions pandas/core/arrays/arrow/_arrow_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pandas.util._decorators import deprecate_kwarg
from pandas.util._exceptions import find_stack_level

from pandas.core.arrays.interval import VALID_CLOSED
from pandas.core.arrays.interval import VALID_INCLUSIVE


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

@property
def inclusive(self) -> IntervalInclusiveType:
return self._closed
return self._inclusive

@property
def closed(self) -> IntervalInclusiveType:
Expand All @@ -135,7 +135,7 @@ def closed(self) -> IntervalInclusiveType:
FutureWarning,
stacklevel=find_stack_level(),
)
return self._closed
return self._inclusive

def __arrow_ext_serialize__(self) -> bytes:
metadata = {"subtype": str(self.subtype), "inclusive": self.inclusive}
Expand Down
Loading