diff --git a/pandas/_libs/interval.pyi b/pandas/_libs/interval.pyi index 4c36246e04d23..587fdf84f2f85 100644 --- a/pandas/_libs/interval.pyi +++ b/pandas/_libs/interval.pyi @@ -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__( diff --git a/pandas/_libs/interval.pyx b/pandas/_libs/interval.pyx index 14b7baf7f5a08..fe405b98f218c 100644 --- a/pandas/_libs/interval.pyx +++ b/pandas/_libs/interval.pyx @@ -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 diff --git a/pandas/core/arrays/interval.py b/pandas/core/arrays/interval.py index b8442205c331e..2ba66006a0645 100644 --- a/pandas/core/arrays/interval.py +++ b/pandas/core/arrays/interval.py @@ -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, diff --git a/pandas/core/dtypes/dtypes.py b/pandas/core/dtypes/dtypes.py index 479bfdc557a07..014d7a4c5a330 100644 --- a/pandas/core/dtypes/dtypes.py +++ b/pandas/core/dtypes/dtypes.py @@ -53,6 +53,7 @@ from pandas._typing import ( Dtype, DtypeObj, + IntervalClosedType, Ordered, npt, type_t, @@ -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, @@ -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) @@ -1175,7 +1176,7 @@ def _can_hold_na(self) -> bool: return True @property - def closed(self): + def closed(self) -> IntervalClosedType: return self._closed @property diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index 13c87a9d06b66..a667506135643 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -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, diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index e2c5ed2ea92b6..8ddf14175a6da 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -65,6 +65,7 @@ AxisInt, FilePath, IndexLabel, + IntervalClosedType, Level, QuantileInterpolation, Scalar, @@ -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: """ @@ -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: """