Skip to content

Commit 10b3032

Browse files
committed
Revert "TYP: Improve typing interval inclusive (pandas-dev#47646)"
This reverts commit 5506476.
1 parent 0b7c648 commit 10b3032

File tree

9 files changed

+38
-47
lines changed

9 files changed

+38
-47
lines changed

pandas/_libs/interval.pyi

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import numpy.typing as npt
1010

1111
from pandas._libs import lib
1212
from pandas._typing import (
13-
IntervalInclusiveType,
13+
IntervalClosedType,
1414
Timedelta,
1515
Timestamp,
1616
)
@@ -54,25 +54,25 @@ class IntervalMixin:
5454

5555
def _warning_interval(
5656
inclusive, closed
57-
) -> tuple[IntervalInclusiveType, lib.NoDefault]: ...
57+
) -> tuple[IntervalClosedType, lib.NoDefault]: ...
5858

5959
class Interval(IntervalMixin, Generic[_OrderableT]):
6060
@property
6161
def left(self: Interval[_OrderableT]) -> _OrderableT: ...
6262
@property
6363
def right(self: Interval[_OrderableT]) -> _OrderableT: ...
6464
@property
65-
def inclusive(self) -> IntervalInclusiveType: ...
65+
def inclusive(self) -> IntervalClosedType: ...
6666
@property
67-
def closed(self) -> IntervalInclusiveType: ...
67+
def closed(self) -> IntervalClosedType: ...
6868
mid: _MidDescriptor
6969
length: _LengthDescriptor
7070
def __init__(
7171
self,
7272
left: _OrderableT,
7373
right: _OrderableT,
74-
inclusive: IntervalInclusiveType = ...,
75-
closed: IntervalInclusiveType = ...,
74+
inclusive: IntervalClosedType = ...,
75+
closed: IntervalClosedType = ...,
7676
) -> None: ...
7777
def __hash__(self) -> int: ...
7878
@overload
@@ -156,14 +156,14 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
156156

157157
def intervals_to_interval_bounds(
158158
intervals: np.ndarray, validate_closed: bool = ...
159-
) -> tuple[np.ndarray, np.ndarray, IntervalInclusiveType]: ...
159+
) -> tuple[np.ndarray, np.ndarray, str]: ...
160160

161161
class IntervalTree(IntervalMixin):
162162
def __init__(
163163
self,
164164
left: np.ndarray,
165165
right: np.ndarray,
166-
inclusive: IntervalInclusiveType = ...,
166+
inclusive: IntervalClosedType = ...,
167167
leaf_size: int = ...,
168168
) -> None: ...
169169
@property

pandas/_typing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def closed(self) -> bool:
313313

314314
# Interval closed type
315315
IntervalLeftRight = Literal["left", "right"]
316-
IntervalInclusiveType = Union[IntervalLeftRight, Literal["both", "neither"]]
316+
IntervalClosedType = Union[IntervalLeftRight, Literal["both", "neither"]]
317317

318318
# datetime and NaTType
319319
DatetimeNaTType = Union[datetime, "NaTType"]

pandas/core/arrays/interval.py

+10-12
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from pandas._typing import (
3434
ArrayLike,
3535
Dtype,
36-
IntervalInclusiveType,
36+
IntervalClosedType,
3737
NpDtype,
3838
PositionalIndexer,
3939
ScalarIndexer,
@@ -231,7 +231,7 @@ def ndim(self) -> Literal[1]:
231231
def __new__(
232232
cls: type[IntervalArrayT],
233233
data,
234-
inclusive: IntervalInclusiveType | None = None,
234+
inclusive: str | None = None,
235235
dtype: Dtype | None = None,
236236
copy: bool = False,
237237
verify_integrity: bool = True,
@@ -278,7 +278,7 @@ def _simple_new(
278278
cls: type[IntervalArrayT],
279279
left,
280280
right,
281-
inclusive: IntervalInclusiveType | None = None,
281+
inclusive=None,
282282
copy: bool = False,
283283
dtype: Dtype | None = None,
284284
verify_integrity: bool = True,
@@ -432,7 +432,7 @@ def _from_factorized(
432432
def from_breaks(
433433
cls: type[IntervalArrayT],
434434
breaks,
435-
inclusive: IntervalInclusiveType | None = None,
435+
inclusive: IntervalClosedType | None = None,
436436
copy: bool = False,
437437
dtype: Dtype | None = None,
438438
) -> IntervalArrayT:
@@ -514,7 +514,7 @@ def from_arrays(
514514
cls: type[IntervalArrayT],
515515
left,
516516
right,
517-
inclusive: IntervalInclusiveType | None = None,
517+
inclusive: IntervalClosedType | None = None,
518518
copy: bool = False,
519519
dtype: Dtype | None = None,
520520
) -> IntervalArrayT:
@@ -587,7 +587,7 @@ def from_arrays(
587587
def from_tuples(
588588
cls: type[IntervalArrayT],
589589
data,
590-
inclusive: IntervalInclusiveType | None = None,
590+
inclusive=None,
591591
copy: bool = False,
592592
dtype: Dtype | None = None,
593593
) -> IntervalArrayT:
@@ -1362,15 +1362,15 @@ def overlaps(self, other):
13621362
# ---------------------------------------------------------------------
13631363

13641364
@property
1365-
def inclusive(self) -> IntervalInclusiveType:
1365+
def inclusive(self) -> IntervalClosedType:
13661366
"""
13671367
Whether the intervals are closed on the left-side, right-side, both or
13681368
neither.
13691369
"""
13701370
return self.dtype.inclusive
13711371

13721372
@property
1373-
def closed(self) -> IntervalInclusiveType:
1373+
def closed(self) -> IntervalClosedType:
13741374
"""
13751375
String describing the inclusive side the intervals.
13761376
@@ -1424,9 +1424,7 @@ def closed(self) -> IntervalInclusiveType:
14241424
),
14251425
}
14261426
)
1427-
def set_closed(
1428-
self: IntervalArrayT, closed: IntervalInclusiveType
1429-
) -> IntervalArrayT:
1427+
def set_closed(self: IntervalArrayT, closed: IntervalClosedType) -> IntervalArrayT:
14301428
warnings.warn(
14311429
"set_closed is deprecated and will be removed in a future version. "
14321430
"Use set_inclusive instead.",
@@ -1477,7 +1475,7 @@ def set_closed(
14771475
}
14781476
)
14791477
def set_inclusive(
1480-
self: IntervalArrayT, inclusive: IntervalInclusiveType
1478+
self: IntervalArrayT, inclusive: IntervalClosedType
14811479
) -> IntervalArrayT:
14821480
if inclusive not in VALID_CLOSED:
14831481
msg = f"invalid option for 'inclusive': {inclusive}"

pandas/core/dtypes/dtypes.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
from pandas._typing import (
4040
Dtype,
4141
DtypeObj,
42-
IntervalInclusiveType,
4342
Ordered,
4443
npt,
4544
type_t,
@@ -1096,7 +1095,7 @@ class IntervalDtype(PandasExtensionDtype):
10961095
def __new__(
10971096
cls,
10981097
subtype=None,
1099-
inclusive: IntervalInclusiveType | None = None,
1098+
inclusive: str_type | None = None,
11001099
closed: None | lib.NoDefault = lib.no_default,
11011100
):
11021101
from pandas.core.dtypes.common import (
@@ -1145,11 +1144,7 @@ def __new__(
11451144
"'inclusive' keyword does not match value "
11461145
"specified in dtype string"
11471146
)
1148-
# Incompatible types in assignment (expression has type
1149-
# "Union[str, Any]", variable has type
1150-
# "Optional[Union[Literal['left', 'right'],
1151-
# Literal['both', 'neither']]]")
1152-
inclusive = gd["inclusive"] # type: ignore[assignment]
1147+
inclusive = gd["inclusive"]
11531148

11541149
try:
11551150
subtype = pandas_dtype(subtype)

pandas/core/generic.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
IgnoreRaise,
5757
IndexKeyFunc,
5858
IndexLabel,
59-
IntervalInclusiveType,
59+
IntervalClosedType,
6060
JSONSerializable,
6161
Level,
6262
Manager,
@@ -8221,7 +8221,7 @@ def between_time(
82218221
end_time,
82228222
include_start: bool_t | lib.NoDefault = lib.no_default,
82238223
include_end: bool_t | lib.NoDefault = lib.no_default,
8224-
inclusive: IntervalInclusiveType | None = None,
8224+
inclusive: IntervalClosedType | None = None,
82258225
axis=None,
82268226
) -> NDFrameT:
82278227
"""
@@ -8327,7 +8327,7 @@ def between_time(
83278327
left = True if include_start is lib.no_default else include_start
83288328
right = True if include_end is lib.no_default else include_end
83298329

8330-
inc_dict: dict[tuple[bool_t, bool_t], IntervalInclusiveType] = {
8330+
inc_dict: dict[tuple[bool_t, bool_t], IntervalClosedType] = {
83318331
(True, True): "both",
83328332
(True, False): "left",
83338333
(False, True): "right",

pandas/core/indexes/datetimes.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
from pandas._typing import (
3838
Dtype,
3939
DtypeObj,
40-
IntervalInclusiveType,
40+
IntervalClosedType,
4141
IntervalLeftRight,
4242
npt,
4343
)
@@ -926,7 +926,7 @@ def date_range(
926926
normalize: bool = False,
927927
name: Hashable = None,
928928
closed: Literal["left", "right"] | None | lib.NoDefault = lib.no_default,
929-
inclusive: IntervalInclusiveType | None = None,
929+
inclusive: IntervalClosedType | None = None,
930930
**kwargs,
931931
) -> DatetimeIndex:
932932
"""
@@ -1132,7 +1132,7 @@ def bdate_range(
11321132
weekmask=None,
11331133
holidays=None,
11341134
closed: IntervalLeftRight | lib.NoDefault | None = lib.no_default,
1135-
inclusive: IntervalInclusiveType | None = None,
1135+
inclusive: IntervalClosedType | None = None,
11361136
**kwargs,
11371137
) -> DatetimeIndex:
11381138
"""

pandas/core/indexes/interval.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from pandas._typing import (
3232
Dtype,
3333
DtypeObj,
34-
IntervalInclusiveType,
34+
IntervalClosedType,
3535
npt,
3636
)
3737
from pandas.errors import InvalidIndexError
@@ -199,7 +199,7 @@ class IntervalIndex(ExtensionIndex):
199199
_typ = "intervalindex"
200200

201201
# annotate properties pinned via inherit_names
202-
inclusive: IntervalInclusiveType
202+
inclusive: IntervalClosedType
203203
is_non_overlapping_monotonic: bool
204204
closed_left: bool
205205
closed_right: bool
@@ -218,7 +218,7 @@ class IntervalIndex(ExtensionIndex):
218218
def __new__(
219219
cls,
220220
data,
221-
inclusive: IntervalInclusiveType | None = None,
221+
inclusive=None,
222222
dtype: Dtype | None = None,
223223
copy: bool = False,
224224
name: Hashable = None,
@@ -267,7 +267,7 @@ def closed(self):
267267
def from_breaks(
268268
cls,
269269
breaks,
270-
inclusive: IntervalInclusiveType | None = None,
270+
inclusive=None,
271271
name: Hashable = None,
272272
copy: bool = False,
273273
dtype: Dtype | None = None,
@@ -303,7 +303,7 @@ def from_arrays(
303303
cls,
304304
left,
305305
right,
306-
inclusive: IntervalInclusiveType | None = None,
306+
inclusive=None,
307307
name: Hashable = None,
308308
copy: bool = False,
309309
dtype: Dtype | None = None,
@@ -338,7 +338,7 @@ def from_arrays(
338338
def from_tuples(
339339
cls,
340340
data,
341-
inclusive: IntervalInclusiveType | None = None,
341+
inclusive=None,
342342
name: Hashable = None,
343343
copy: bool = False,
344344
dtype: Dtype | None = None,
@@ -990,7 +990,7 @@ def interval_range(
990990
periods=None,
991991
freq=None,
992992
name: Hashable = None,
993-
inclusive: IntervalInclusiveType | None = None,
993+
inclusive: IntervalClosedType | None = None,
994994
) -> IntervalIndex:
995995
"""
996996
Return a fixed frequency IntervalIndex.

pandas/io/formats/style.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
Axis,
2727
FilePath,
2828
IndexLabel,
29-
IntervalInclusiveType,
3029
Level,
3130
QuantileInterpolation,
3231
Scalar,
@@ -3489,7 +3488,7 @@ def highlight_between(
34893488
axis: Axis | None = 0,
34903489
left: Scalar | Sequence | None = None,
34913490
right: Scalar | Sequence | None = None,
3492-
inclusive: IntervalInclusiveType = "both",
3491+
inclusive: str = "both",
34933492
props: str | None = None,
34943493
) -> Styler:
34953494
"""
@@ -3594,7 +3593,7 @@ def highlight_quantile(
35943593
q_left: float = 0.0,
35953594
q_right: float = 1.0,
35963595
interpolation: QuantileInterpolation = "linear",
3597-
inclusive: IntervalInclusiveType = "both",
3596+
inclusive: str = "both",
35983597
props: str | None = None,
35993598
) -> Styler:
36003599
"""
@@ -3979,7 +3978,7 @@ def _highlight_between(
39793978
props: str,
39803979
left: Scalar | Sequence | np.ndarray | NDFrame | None = None,
39813980
right: Scalar | Sequence | np.ndarray | NDFrame | None = None,
3982-
inclusive: bool | IntervalInclusiveType = True,
3981+
inclusive: bool | str = True,
39833982
) -> np.ndarray:
39843983
"""
39853984
Return an array of css props based on condition of data values within given range.

pandas/util/_validators.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import numpy as np
1818

19-
from pandas._typing import IntervalInclusiveType
2019
from pandas.util._exceptions import find_stack_level
2120

2221
from pandas.core.dtypes.common import (
@@ -494,7 +493,7 @@ def validate_endpoints(closed: str | None) -> tuple[bool, bool]:
494493
return left_closed, right_closed
495494

496495

497-
def validate_inclusive(inclusive: IntervalInclusiveType | None) -> tuple[bool, bool]:
496+
def validate_inclusive(inclusive: str | None) -> tuple[bool, bool]:
498497
"""
499498
Check that the `inclusive` argument is among {"both", "neither", "left", "right"}.
500499

0 commit comments

Comments
 (0)