Skip to content

TYP: replaced IntervalClosedType to IntervalInclusiveType #52726

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

Closed
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: 4 additions & 4 deletions pandas/_libs/interval.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import numpy as np
import numpy.typing as npt

from pandas._typing import (
IntervalClosedType,
IntervalInclusiveType,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, sorry the explanation during the sprint might have been confusing. I was referring to adding IntervalClosedType where this is not added yet, not renaming. Sorry for this.

Timedelta,
Timestamp,
)
Expand Down Expand Up @@ -57,14 +57,14 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
@property
def right(self: Interval[_OrderableT]) -> _OrderableT: ...
@property
def closed(self) -> IntervalClosedType: ...
def closed(self) -> IntervalInclusiveType: ...
mid: _MidDescriptor
length: _LengthDescriptor
def __init__(
self,
left: _OrderableT,
right: _OrderableT,
closed: IntervalClosedType = ...,
closed: IntervalInclusiveType = ...,
) -> None: ...
def __hash__(self) -> int: ...
@overload
Expand Down Expand Up @@ -155,7 +155,7 @@ class IntervalTree(IntervalMixin):
self,
left: np.ndarray,
right: np.ndarray,
closed: IntervalClosedType = ...,
closed: IntervalInclusiveType = ...,
leaf_size: int = ...,
) -> None: ...
@property
Expand Down
2 changes: 1 addition & 1 deletion pandas/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def closed(self) -> bool:

# Interval closed type
IntervalLeftRight = Literal["left", "right"]
IntervalClosedType = Union[IntervalLeftRight, Literal["both", "neither"]]
IntervalInclusiveType = Union[IntervalLeftRight, Literal["both", "neither"]]

# datetime and NaTType
DatetimeNaTType = Union[datetime, "NaTType"]
Expand Down
8 changes: 4 additions & 4 deletions pandas/core/arrays/arrow/extension_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from pandas.core.arrays.interval import VALID_CLOSED

if TYPE_CHECKING:
from pandas._typing import IntervalClosedType
from pandas._typing import IntervalInclusiveType


class ArrowPeriodType(pyarrow.ExtensionType):
Expand Down Expand Up @@ -58,11 +58,11 @@ def to_pandas_dtype(self):


class ArrowIntervalType(pyarrow.ExtensionType):
def __init__(self, subtype, closed: IntervalClosedType) -> None:
def __init__(self, subtype, closed: IntervalInclusiveType) -> None:
# attributes need to be set first before calling
# super init (as that calls serialize)
assert closed in VALID_CLOSED
self._closed: IntervalClosedType = closed
self._closed: IntervalInclusiveType = closed
if not isinstance(subtype, pyarrow.DataType):
subtype = pyarrow.type_for_alias(str(subtype))
self._subtype = subtype
Expand All @@ -75,7 +75,7 @@ def subtype(self):
return self._subtype

@property
def closed(self) -> IntervalClosedType:
def closed(self) -> IntervalInclusiveType:
return self._closed

def __arrow_ext_serialize__(self) -> bytes:
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
if TYPE_CHECKING:
from pandas._typing import (
DateTimeErrorChoices,
IntervalClosedType,
IntervalInclusiveType,
Self,
TimeAmbiguous,
TimeNonexistent,
Expand Down Expand Up @@ -384,7 +384,7 @@ def _generate_range( # type: ignore[override]
normalize: bool = False,
ambiguous: TimeAmbiguous = "raise",
nonexistent: TimeNonexistent = "raise",
inclusive: IntervalClosedType = "both",
inclusive: IntervalInclusiveType = "both",
*,
unit: str | None = None,
) -> Self:
Expand Down
14 changes: 7 additions & 7 deletions pandas/core/arrays/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
ArrayLike,
AxisInt,
Dtype,
IntervalClosedType,
IntervalInclusiveType,
NpDtype,
PositionalIndexer,
ScalarIndexer,
Expand Down Expand Up @@ -293,7 +293,7 @@ def _ensure_simple_new_inputs(
cls,
left,
right,
closed: IntervalClosedType | None = None,
closed: IntervalInclusiveType | None = None,
copy: bool = False,
dtype: Dtype | None = None,
) -> tuple[IntervalSideT, IntervalSideT, IntervalDtype]:
Expand Down Expand Up @@ -444,7 +444,7 @@ def _from_factorized(cls, values: np.ndarray, original: IntervalArray) -> Self:
def from_breaks(
cls,
breaks,
closed: IntervalClosedType | None = "right",
closed: IntervalInclusiveType | None = "right",
copy: bool = False,
dtype: Dtype | None = None,
) -> Self:
Expand Down Expand Up @@ -522,7 +522,7 @@ def from_arrays(
cls,
left,
right,
closed: IntervalClosedType | None = "right",
closed: IntervalInclusiveType | None = "right",
copy: bool = False,
dtype: Dtype | None = None,
) -> Self:
Expand Down Expand Up @@ -594,7 +594,7 @@ def from_arrays(
def from_tuples(
cls,
data,
closed: IntervalClosedType | None = "right",
closed: IntervalInclusiveType | None = "right",
copy: bool = False,
dtype: Dtype | None = None,
) -> Self:
Expand Down Expand Up @@ -1374,7 +1374,7 @@ def overlaps(self, other):
# ---------------------------------------------------------------------

@property
def closed(self) -> IntervalClosedType:
def closed(self) -> IntervalInclusiveType:
"""
String describing the inclusive side the intervals.

Expand Down Expand Up @@ -1421,7 +1421,7 @@ def closed(self) -> IntervalClosedType:
),
}
)
def set_closed(self, closed: IntervalClosedType) -> Self:
def set_closed(self, closed: IntervalInclusiveType) -> Self:
if closed not in VALID_CLOSED:
msg = f"invalid option for 'closed': {closed}"
raise ValueError(msg)
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
IgnoreRaise,
IndexKeyFunc,
IndexLabel,
IntervalClosedType,
IntervalInclusiveType,
JSONSerializable,
Level,
Manager,
Expand Down Expand Up @@ -8507,7 +8507,7 @@ def between_time(
self,
start_time,
end_time,
inclusive: IntervalClosedType = "both",
inclusive: IntervalInclusiveType = "both",
axis: Axis | None = None,
) -> Self:
"""
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
Dtype,
DtypeObj,
Frequency,
IntervalClosedType,
IntervalInclusiveType,
Self,
TimeAmbiguous,
TimeNonexistent,
Expand Down Expand Up @@ -786,7 +786,7 @@ def date_range(
tz=None,
normalize: bool = False,
name: Hashable = None,
inclusive: IntervalClosedType = "both",
inclusive: IntervalInclusiveType = "both",
*,
unit: str | None = None,
**kwargs,
Expand Down Expand Up @@ -989,7 +989,7 @@ def bdate_range(
name: Hashable = None,
weekmask=None,
holidays=None,
inclusive: IntervalClosedType = "both",
inclusive: IntervalInclusiveType = "both",
**kwargs,
) -> DatetimeIndex:
"""
Expand Down
12 changes: 6 additions & 6 deletions pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
from pandas._typing import (
Dtype,
DtypeObj,
IntervalClosedType,
IntervalInclusiveType,
npt,
)
_index_doc_kwargs = dict(ibase._index_doc_kwargs)
Expand Down Expand Up @@ -200,7 +200,7 @@ class IntervalIndex(ExtensionIndex):
_typ = "intervalindex"

# annotate properties pinned via inherit_names
closed: IntervalClosedType
closed: IntervalInclusiveType
is_non_overlapping_monotonic: bool
closed_left: bool
closed_right: bool
Expand Down Expand Up @@ -261,7 +261,7 @@ def __new__(
def from_breaks(
cls,
breaks,
closed: IntervalClosedType | None = "right",
closed: IntervalInclusiveType | None = "right",
name: Hashable = None,
copy: bool = False,
dtype: Dtype | None = None,
Expand Down Expand Up @@ -297,7 +297,7 @@ def from_arrays(
cls,
left,
right,
closed: IntervalClosedType = "right",
closed: IntervalInclusiveType = "right",
name: Hashable = None,
copy: bool = False,
dtype: Dtype | None = None,
Expand Down Expand Up @@ -332,7 +332,7 @@ def from_arrays(
def from_tuples(
cls,
data,
closed: IntervalClosedType = "right",
closed: IntervalInclusiveType = "right",
name: Hashable = None,
copy: bool = False,
dtype: Dtype | None = None,
Expand Down Expand Up @@ -983,7 +983,7 @@ def interval_range(
periods=None,
freq=None,
name: Hashable = None,
closed: IntervalClosedType = "right",
closed: IntervalInclusiveType = "right",
) -> IntervalIndex:
"""
Return a fixed frequency IntervalIndex.
Expand Down