Skip to content

added typing IntervalClosedType where needed #52894

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

Merged
merged 9 commits into from
Apr 25, 2023
2 changes: 1 addition & 1 deletion pandas/_libs/interval.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):

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

class IntervalTree(IntervalMixin):
def __init__(
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/interval.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ def intervals_to_interval_bounds(ndarray intervals, bint validate_closed=True):
tuple of
left : ndarray
right : ndarray
closed: str
closed: IntervalClosedType
"""
cdef:
object closed = None, interval
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def ndim(self) -> Literal[1]:
def __new__(
cls,
data,
closed=None,
closed: IntervalClosedType | None = None,
dtype: Dtype | None = None,
copy: bool = False,
verify_integrity: bool = True,
Expand Down
7 changes: 4 additions & 3 deletions pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
from pandas._typing import (
Dtype,
DtypeObj,
IntervalClosedType,
Ordered,
npt,
type_t,
Expand Down Expand Up @@ -1099,7 +1100,7 @@ class IntervalDtype(PandasExtensionDtype):

_cache_dtypes: dict[str_type, PandasExtensionDtype] = {}

def __new__(cls, subtype=None, closed: str_type | None = None):
def __new__(cls, subtype=None, closed: IntervalClosedType | None = None):
from pandas.core.dtypes.common import (
is_string_dtype,
pandas_dtype,
Expand Down Expand Up @@ -1137,7 +1138,7 @@ def __new__(cls, subtype=None, closed: str_type | None = None):
"'closed' keyword does not match value "
"specified in dtype string"
)
closed = gd["closed"]
closed = gd["closed"] # type: ignore[assignment]

try:
subtype = pandas_dtype(subtype)
Expand Down Expand Up @@ -1175,7 +1176,7 @@ def _can_hold_na(self) -> bool:
return True

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

@property
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class IntervalIndex(ExtensionIndex):
def __new__(
cls,
data,
closed=None,
closed: IntervalClosedType | None = None,
dtype: Dtype | None = None,
copy: bool = False,
name: Hashable = None,
Expand Down
5 changes: 3 additions & 2 deletions pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
AxisInt,
FilePath,
IndexLabel,
IntervalClosedType,
Level,
QuantileInterpolation,
Scalar,
Expand Down Expand Up @@ -3185,7 +3186,7 @@ def highlight_between(
axis: Axis | None = 0,
left: Scalar | Sequence | None = None,
right: Scalar | Sequence | None = None,
inclusive: str = "both",
inclusive: IntervalClosedType = "both",
props: str | None = None,
) -> Styler:
"""
Expand Down Expand Up @@ -3294,7 +3295,7 @@ def highlight_quantile(
q_left: float = 0.0,
q_right: float = 1.0,
interpolation: QuantileInterpolation = "linear",
inclusive: str = "both",
inclusive: IntervalClosedType = "both",
props: str | None = None,
) -> Styler:
"""
Expand Down