Skip to content

Commit c7804a2

Browse files
committed
Merge remote-tracking branch 'upstream/main' into pandas-arrays
2 parents 09bde05 + dc9a094 commit c7804a2

File tree

11 files changed

+992
-138
lines changed

11 files changed

+992
-138
lines changed

pandas-stubs/_libs/interval.pyi

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
from typing import (
22
Any,
33
Generic,
4+
Literal,
45
TypeVar,
56
overload,
67
)
78

89
import numpy as np
910
from pandas import (
11+
IntervalIndex,
12+
Series,
1013
Timedelta,
1114
Timestamp,
1215
)
1316

1417
from pandas._typing import (
1518
IntervalClosedType,
19+
IntervalT,
20+
np_ndarray_bool,
1621
npt,
1722
)
1823

@@ -121,28 +126,73 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
121126
@overload
122127
def __mul__(self: Interval[float], y: float) -> Interval[float]: ...
123128
@overload
129+
def __mul__(self: Interval[Timedelta], y: float) -> Interval[Timedelta]: ...
130+
@overload
124131
def __rmul__(
125132
self: Interval[int], y: _OrderableScalarT
126133
) -> Interval[_OrderableScalarT]: ...
127134
@overload
128135
def __rmul__(self: Interval[float], y: float) -> Interval[float]: ...
129136
@overload
130-
def __truediv__(
131-
self: Interval[int], y: _OrderableScalarT
132-
) -> Interval[_OrderableScalarT]: ...
137+
def __rmul__(self: Interval[Timedelta], y: float) -> Interval[Timedelta]: ...
138+
@overload
139+
def __truediv__(self: Interval[int], y: _OrderableScalarT) -> Interval[float]: ...
133140
@overload
134141
def __truediv__(self: Interval[float], y: float) -> Interval[float]: ...
135142
@overload
143+
def __truediv__(self: Interval[Timedelta], y: float) -> Interval[Timedelta]: ...
144+
@overload
136145
def __floordiv__(
137146
self: Interval[int], y: _OrderableScalarT
138147
) -> Interval[_OrderableScalarT]: ...
139148
@overload
140149
def __floordiv__(self: Interval[float], y: float) -> Interval[float]: ...
150+
@overload
151+
def __floordiv__(self: Interval[Timedelta], y: float) -> Interval[Timedelta]: ...
152+
@overload
141153
def overlaps(self: Interval[_OrderableT], other: Interval[_OrderableT]) -> bool: ...
142-
143-
def intervals_to_interval_bounds(
144-
intervals: np.ndarray, validate_closed: bool = ...
145-
) -> tuple[np.ndarray, np.ndarray, str]: ...
154+
@overload
155+
def overlaps(self: Interval[int], other: Interval[float]) -> bool: ...
156+
@overload
157+
def overlaps(self: Interval[float], other: Interval[int]) -> bool: ...
158+
@overload
159+
def __gt__(self, other: Interval[_OrderableT]) -> bool: ...
160+
@overload
161+
def __gt__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ...
162+
@overload
163+
def __gt__(self, other: Series[_OrderableT]) -> Series[bool]: ...
164+
@overload
165+
def __lt__(self, other: Interval[_OrderableT]) -> bool: ...
166+
@overload
167+
def __lt__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ...
168+
@overload
169+
def __lt__(self, other: Series[_OrderableT]) -> Series[bool]: ...
170+
@overload
171+
def __ge__(self, other: Interval[_OrderableT]) -> bool: ...
172+
@overload
173+
def __ge__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ...
174+
@overload
175+
def __ge__(self, other: Series[_OrderableT]) -> Series[bool]: ...
176+
@overload
177+
def __le__(self, other: Interval[_OrderableT]) -> bool: ...
178+
@overload
179+
def __le__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ...
180+
@overload
181+
def __eq__(self, other: Interval[_OrderableT]) -> bool: ... # type: ignore[misc]
182+
@overload
183+
def __eq__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ... # type: ignore[misc]
184+
@overload
185+
def __eq__(self, other: Series[_OrderableT]) -> Series[bool]: ... # type: ignore[misc]
186+
@overload
187+
def __eq__(self, other: object) -> Literal[False]: ...
188+
@overload
189+
def __ne__(self, other: Interval[_OrderableT]) -> bool: ... # type: ignore[misc]
190+
@overload
191+
def __ne__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ... # type: ignore[misc]
192+
@overload
193+
def __ne__(self, other: Series[_OrderableT]) -> Series[bool]: ... # type: ignore[misc]
194+
@overload
195+
def __ne__(self, other: object) -> Literal[True]: ...
146196

147197
class IntervalTree(IntervalMixin):
148198
def __init__(

pandas-stubs/_typing.pyi

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ from pandas.core.indexes.base import Index
2626
from pandas.core.series import Series
2727
from typing_extensions import TypeAlias
2828

29+
from pandas._libs.interval import Interval
2930
from pandas._libs.tslibs import (
3031
Period,
3132
Timedelta,
@@ -196,6 +197,10 @@ S1 = TypeVar(
196197
Timedelta,
197198
np.datetime64,
198199
Period,
200+
Interval[int],
201+
Interval[float],
202+
Interval[Timestamp],
203+
Interval[Timedelta],
199204
)
200205
T1 = TypeVar(
201206
"T1", str, int, np.int64, np.uint64, np.float64, float, np.dtype[np.generic]
@@ -220,7 +225,13 @@ NDFrameT = TypeVar("NDFrameT", bound=NDFrame)
220225
IndexT = TypeVar("IndexT", bound=Index)
221226

222227
# Interval closed type
223-
228+
IntervalT = TypeVar(
229+
"IntervalT",
230+
Interval[int],
231+
Interval[float],
232+
Interval[Timestamp],
233+
Interval[Timedelta],
234+
)
224235
IntervalClosedType: TypeAlias = Literal["left", "right", "both", "neither"]
225236

226237
IgnoreRaiseCoerce: TypeAlias = Literal["ignore", "raise", "coerce"]

pandas-stubs/_version.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ version_json: str = ...
44

55
def get_versions(): ...
66

7-
_stub_version: Literal["1.5.1.221024"]
7+
_stub_version: Literal["1.5.2.221124"]

pandas-stubs/core/algorithms.pyi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,20 @@ from pandas import (
1414
)
1515
from pandas.api.extensions import ExtensionArray
1616

17-
from pandas._typing import AnyArrayLike
17+
from pandas._typing import (
18+
AnyArrayLike,
19+
IntervalT,
20+
)
1821

1922
# These are type: ignored because the Index types overlap due to inheritance but indices
2023
# with extension types return the same type while standard type return ndarray
24+
2125
@overload
2226
def unique(values: PeriodIndex) -> PeriodIndex: ... # type: ignore[misc]
2327
@overload
2428
def unique(values: CategoricalIndex) -> CategoricalIndex: ... # type: ignore[misc]
2529
@overload
26-
def unique(values: IntervalIndex) -> IntervalIndex: ... # type: ignore[misc]
30+
def unique(values: IntervalIndex[IntervalT]) -> IntervalIndex[IntervalT]: ... # type: ignore[misc]
2731
@overload
2832
def unique(values: Index) -> np.ndarray: ...
2933
@overload

0 commit comments

Comments
 (0)