Skip to content

Commit 95666b6

Browse files
gmollardYi Wei
authored and
Yi Wei
committed
TYP: Added IntervalClosedType where needed (pandas-dev#52894)
1 parent bb42751 commit 95666b6

File tree

6 files changed

+11
-9
lines changed

6 files changed

+11
-9
lines changed

pandas/_libs/interval.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
148148

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

153153
class IntervalTree(IntervalMixin):
154154
def __init__(

pandas/_libs/interval.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ def intervals_to_interval_bounds(ndarray intervals, bint validate_closed=True):
612612
tuple of
613613
left : ndarray
614614
right : ndarray
615-
closed: str
615+
closed: IntervalClosedType
616616
"""
617617
cdef:
618618
object closed = None, interval

pandas/core/arrays/interval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def ndim(self) -> Literal[1]:
226226
def __new__(
227227
cls,
228228
data,
229-
closed=None,
229+
closed: IntervalClosedType | None = None,
230230
dtype: Dtype | None = None,
231231
copy: bool = False,
232232
verify_integrity: bool = True,

pandas/core/dtypes/dtypes.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
from pandas._typing import (
5454
Dtype,
5555
DtypeObj,
56+
IntervalClosedType,
5657
Ordered,
5758
npt,
5859
type_t,
@@ -1099,7 +1100,7 @@ class IntervalDtype(PandasExtensionDtype):
10991100

11001101
_cache_dtypes: dict[str_type, PandasExtensionDtype] = {}
11011102

1102-
def __new__(cls, subtype=None, closed: str_type | None = None):
1103+
def __new__(cls, subtype=None, closed: IntervalClosedType | None = None):
11031104
from pandas.core.dtypes.common import (
11041105
is_string_dtype,
11051106
pandas_dtype,
@@ -1137,7 +1138,7 @@ def __new__(cls, subtype=None, closed: str_type | None = None):
11371138
"'closed' keyword does not match value "
11381139
"specified in dtype string"
11391140
)
1140-
closed = gd["closed"]
1141+
closed = gd["closed"] # type: ignore[assignment]
11411142

11421143
try:
11431144
subtype = pandas_dtype(subtype)
@@ -1175,7 +1176,7 @@ def _can_hold_na(self) -> bool:
11751176
return True
11761177

11771178
@property
1178-
def closed(self):
1179+
def closed(self) -> IntervalClosedType:
11791180
return self._closed
11801181

11811182
@property

pandas/core/indexes/interval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ class IntervalIndex(ExtensionIndex):
220220
def __new__(
221221
cls,
222222
data,
223-
closed=None,
223+
closed: IntervalClosedType | None = None,
224224
dtype: Dtype | None = None,
225225
copy: bool = False,
226226
name: Hashable = None,

pandas/io/formats/style.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
AxisInt,
6666
FilePath,
6767
IndexLabel,
68+
IntervalClosedType,
6869
Level,
6970
QuantileInterpolation,
7071
Scalar,
@@ -3185,7 +3186,7 @@ def highlight_between(
31853186
axis: Axis | None = 0,
31863187
left: Scalar | Sequence | None = None,
31873188
right: Scalar | Sequence | None = None,
3188-
inclusive: str = "both",
3189+
inclusive: IntervalClosedType = "both",
31893190
props: str | None = None,
31903191
) -> Styler:
31913192
"""
@@ -3294,7 +3295,7 @@ def highlight_quantile(
32943295
q_left: float = 0.0,
32953296
q_right: float = 1.0,
32963297
interpolation: QuantileInterpolation = "linear",
3297-
inclusive: str = "both",
3298+
inclusive: IntervalClosedType = "both",
32983299
props: str | None = None,
32993300
) -> Styler:
33003301
"""

0 commit comments

Comments
 (0)