Skip to content

Commit f4c2bb8

Browse files
committed
Merge branch 'main' of github.com:pandas-dev/pandas-stubs into feature/python314
2 parents acf2112 + 42192e0 commit f4c2bb8

File tree

13 files changed

+134
-130
lines changed

13 files changed

+134
-130
lines changed

pandas-stubs/_libs/tslibs/period.pyi

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
import datetime
2+
import sys
23
from typing import (
34
Literal,
45
TypeAlias,
56
overload,
67
)
78

89
import numpy as np
9-
from pandas import (
10-
Index,
11-
PeriodIndex,
12-
Series,
13-
Timedelta,
14-
TimedeltaIndex,
15-
)
10+
from pandas.core.indexes.base import Index
11+
from pandas.core.indexes.period import PeriodIndex
12+
from pandas.core.indexes.timedeltas import TimedeltaIndex
13+
from pandas.core.series import Series
1614
from typing_extensions import Self
1715

1816
from pandas._libs.tslibs import NaTType
19-
from pandas._libs.tslibs.offsets import (
20-
BaseOffset,
21-
)
17+
from pandas._libs.tslibs.offsets import BaseOffset
18+
from pandas._libs.tslibs.timedeltas import Timedelta
2219
from pandas._libs.tslibs.timestamps import Timestamp
2320
from pandas._typing import (
2421
PeriodFrequency,
@@ -79,7 +76,7 @@ class Period(PeriodMixin):
7976
@overload
8077
def __sub__(self, other: _PeriodAddSub) -> Period: ...
8178
@overload
82-
def __sub__(self, other: Period) -> BaseOffset: ...
79+
def __sub__(self, other: Self) -> BaseOffset: ...
8380
@overload
8481
def __sub__(self, other: NaTType) -> NaTType: ...
8582
@overload
@@ -98,8 +95,13 @@ class Period(PeriodMixin):
9895
def __add__(self, other: Index) -> PeriodIndex: ...
9996
# Ignored due to indecipherable error from mypy:
10097
# Forward operator "__add__" is not callable [misc]
101-
@overload
102-
def __radd__(self, other: _PeriodAddSub) -> Self: ... # type: ignore[misc]
98+
if sys.version_info >= (3, 11):
99+
@overload
100+
def __radd__(self, other: _PeriodAddSub) -> Self: ...
101+
else:
102+
@overload
103+
def __radd__(self, other: _PeriodAddSub) -> Self: ... # type: ignore[misc]
104+
103105
@overload
104106
def __radd__(self, other: NaTType) -> NaTType: ...
105107
# Real signature is -> PeriodIndex, but conflicts with Index.__add__
@@ -111,7 +113,7 @@ class Period(PeriodMixin):
111113
# ignore[misc] here because we know all other comparisons
112114
# are False, so we use Literal[False]
113115
@overload
114-
def __eq__(self, other: Period) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
116+
def __eq__(self, other: Self) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
115117
@overload
116118
def __eq__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
117119
@overload
@@ -121,7 +123,7 @@ class Period(PeriodMixin):
121123
@overload
122124
def __eq__(self, other: object) -> Literal[False]: ...
123125
@overload
124-
def __ge__(self, other: Period) -> bool: ...
126+
def __ge__(self, other: Self) -> bool: ...
125127
@overload
126128
def __ge__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
127129
@overload
@@ -133,7 +135,7 @@ class Period(PeriodMixin):
133135
self, other: np_ndarray[ShapeT, np.object_]
134136
) -> np_ndarray[ShapeT, np.bool]: ...
135137
@overload
136-
def __gt__(self, other: Period) -> bool: ...
138+
def __gt__(self, other: Self) -> bool: ...
137139
@overload
138140
def __gt__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
139141
@overload
@@ -145,7 +147,7 @@ class Period(PeriodMixin):
145147
self, other: np_ndarray[ShapeT, np.object_]
146148
) -> np_ndarray[ShapeT, np.bool]: ...
147149
@overload
148-
def __le__(self, other: Period) -> bool: ...
150+
def __le__(self, other: Self) -> bool: ...
149151
@overload
150152
def __le__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
151153
@overload
@@ -157,7 +159,7 @@ class Period(PeriodMixin):
157159
self, other: np_ndarray[ShapeT, np.object_]
158160
) -> np_ndarray[ShapeT, np.bool]: ...
159161
@overload
160-
def __lt__(self, other: Period) -> bool: ...
162+
def __lt__(self, other: Self) -> bool: ...
161163
@overload
162164
def __lt__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
163165
@overload
@@ -171,7 +173,7 @@ class Period(PeriodMixin):
171173
# ignore[misc] here because we know all other comparisons
172174
# are False, so we use Literal[False]
173175
@overload
174-
def __ne__(self, other: Period) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
176+
def __ne__(self, other: Self) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
175177
@overload
176178
def __ne__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
177179
@overload

pandas-stubs/_libs/tslibs/timedeltas.pyi

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,14 @@ from typing import (
1313
)
1414

1515
import numpy as np
16-
import pandas as pd
17-
from pandas import (
18-
DatetimeIndex,
19-
Index,
20-
PeriodIndex,
21-
Series,
22-
TimedeltaIndex,
23-
)
16+
from pandas.core.indexes.base import Index
17+
from pandas.core.indexes.datetimes import DatetimeIndex
18+
from pandas.core.indexes.period import PeriodIndex
19+
from pandas.core.indexes.timedeltas import TimedeltaIndex
20+
from pandas.core.series import Series
2421
from typing_extensions import Self
2522

26-
from pandas._libs.tslibs import (
27-
NaTType,
28-
)
23+
from pandas._libs.tslibs import NaTType
2924
from pandas._libs.tslibs.period import Period
3025
from pandas._libs.tslibs.timestamps import Timestamp
3126
from pandas._typing import (
@@ -131,7 +126,7 @@ class Timedelta(timedelta):
131126
def to_timedelta64(self) -> np.timedelta64: ...
132127
@property
133128
def asm8(self) -> np.timedelta64: ...
134-
# TODO: round/floor/ceil could return NaT?
129+
# TODO: pandas-dev/pandas-stubs#1432 round/floor/ceil could return NaT?
135130
def round(self, freq: Frequency) -> Self: ...
136131
def floor(self, freq: Frequency) -> Self: ...
137132
def ceil(self, freq: Frequency) -> Self: ...
@@ -174,17 +169,17 @@ class Timedelta(timedelta):
174169
) -> np_ndarray[ShapeT, np.datetime64]: ...
175170
# Override due to more types supported than timedelta
176171
@overload # type: ignore[override]
177-
def __sub__(self, other: timedelta | Timedelta | np.timedelta64) -> Self: ...
172+
def __sub__(self, other: timedelta | np.timedelta64 | Self) -> Self: ...
178173
@overload
179174
def __sub__(self, other: NaTType) -> NaTType: ...
180175
@overload
181176
def __sub__(
182177
self, other: np_ndarray[ShapeT, np.timedelta64]
183178
) -> np_ndarray[ShapeT, np.timedelta64]: ...
184179
@overload
185-
def __sub__(self, other: pd.TimedeltaIndex) -> TimedeltaIndex: ...
180+
def __sub__(self, other: TimedeltaIndex) -> TimedeltaIndex: ...
186181
@overload
187-
def __rsub__(self, other: timedelta | Timedelta | np.timedelta64) -> Self: ...
182+
def __rsub__(self, other: timedelta | np.timedelta64 | Self) -> Self: ...
188183
@overload
189184
def __rsub__(self, other: datetime | Timestamp | np.datetime64) -> Timestamp: ... # type: ignore[misc]
190185
@overload
@@ -204,7 +199,7 @@ class Timedelta(timedelta):
204199
self, other: np_ndarray[ShapeT, np.timedelta64]
205200
) -> np_ndarray[ShapeT, np.timedelta64]: ...
206201
@overload
207-
def __rsub__(self, other: pd.TimedeltaIndex) -> pd.TimedeltaIndex: ...
202+
def __rsub__(self, other: TimedeltaIndex) -> TimedeltaIndex: ...
208203
def __neg__(self) -> Self: ...
209204
def __pos__(self) -> Self: ...
210205
def __abs__(self) -> Self: ...
@@ -224,7 +219,7 @@ class Timedelta(timedelta):
224219
# Override due to more types supported than timedelta
225220
# error: Signature of "__floordiv__" incompatible with supertype "timedelta"
226221
@overload # type: ignore[override]
227-
def __floordiv__(self, other: timedelta | Timedelta | np.timedelta64) -> int: ...
222+
def __floordiv__(self, other: timedelta | np.timedelta64 | Self) -> int: ...
228223
@overload
229224
def __floordiv__(self, other: float) -> Self: ...
230225
@overload
@@ -273,9 +268,9 @@ class Timedelta(timedelta):
273268
def __rtruediv__(self, other: timedelta | Timedelta | NaTType) -> float: ...
274269
# Override due to more types supported than timedelta
275270
@overload
276-
def __eq__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
271+
def __eq__(self, other: timedelta | np.timedelta64 | Self) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
277272
@overload
278-
def __eq__(self, other: Series[pd.Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
273+
def __eq__(self, other: Series[Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
279274
@overload
280275
def __eq__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
281276
@overload
@@ -286,9 +281,9 @@ class Timedelta(timedelta):
286281
def __eq__(self, other: object) -> Literal[False]: ...
287282
# Override due to more types supported than timedelta
288283
@overload
289-
def __ne__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
284+
def __ne__(self, other: timedelta | np.timedelta64 | Self) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
290285
@overload
291-
def __ne__(self, other: Series[pd.Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
286+
def __ne__(self, other: Series[Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
292287
@overload
293288
def __ne__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
294289
@overload
@@ -315,52 +310,50 @@ class Timedelta(timedelta):
315310
self, other: Series[int] | Series[float] | Series[Timedelta]
316311
) -> Series[Timedelta]: ...
317312
def __divmod__(self, other: timedelta) -> tuple[int, Timedelta]: ...
318-
# Mypy complains Forward operator "<inequality op>" is not callable, so ignore misc
319-
# for le, lt ge and gt
320313
# Override due to more types supported than timedelta
321314
@overload # type: ignore[override]
322-
def __le__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
315+
def __le__(self, other: timedelta | np.timedelta64 | Self) -> bool: ...
323316
@overload
324317
def __le__(self, other: TimedeltaIndex) -> np_1darray[np.bool]: ...
325318
@overload
326319
def __le__(
327320
self, other: np_ndarray[ShapeT, np.timedelta64]
328321
) -> np_ndarray[ShapeT, np.bool_]: ...
329322
@overload
330-
def __le__(self, other: Series[pd.Timedelta]) -> Series[bool]: ...
323+
def __le__(self, other: Series[Timedelta]) -> Series[bool]: ...
331324
# Override due to more types supported than timedelta
332325
@overload # type: ignore[override]
333-
def __lt__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
326+
def __lt__(self, other: timedelta | np.timedelta64 | Self) -> bool: ...
334327
@overload
335328
def __lt__(self, other: TimedeltaIndex) -> np_1darray[np.bool]: ...
336329
@overload
337330
def __lt__(
338331
self, other: np_ndarray[ShapeT, np.timedelta64]
339332
) -> np_ndarray[ShapeT, np.bool_]: ...
340333
@overload
341-
def __lt__(self, other: Series[pd.Timedelta]) -> Series[bool]: ...
334+
def __lt__(self, other: Series[Timedelta]) -> Series[bool]: ...
342335
# Override due to more types supported than timedelta
343336
@overload # type: ignore[override]
344-
def __ge__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
337+
def __ge__(self, other: timedelta | np.timedelta64 | Self) -> bool: ...
345338
@overload
346339
def __ge__(self, other: TimedeltaIndex) -> np_1darray[np.bool]: ...
347340
@overload
348341
def __ge__(
349342
self, other: np_ndarray[ShapeT, np.timedelta64]
350343
) -> np_ndarray[ShapeT, np.bool_]: ...
351344
@overload
352-
def __ge__(self, other: Series[pd.Timedelta]) -> Series[bool]: ...
345+
def __ge__(self, other: Series[Timedelta]) -> Series[bool]: ...
353346
# Override due to more types supported than timedelta
354347
@overload # type: ignore[override]
355-
def __gt__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
348+
def __gt__(self, other: timedelta | np.timedelta64 | Self) -> bool: ...
356349
@overload
357350
def __gt__(self, other: TimedeltaIndex) -> np_1darray[np.bool]: ...
358351
@overload
359352
def __gt__(
360353
self, other: np_ndarray[ShapeT, np.timedelta64]
361354
) -> np_ndarray[ShapeT, np.bool_]: ...
362355
@overload
363-
def __gt__(self, other: Series[pd.Timedelta]) -> Series[bool]: ...
356+
def __gt__(self, other: Series[Timedelta]) -> Series[bool]: ...
364357
def __hash__(self) -> int: ...
365358
def isoformat(self) -> str: ...
366359
def to_numpy(self) -> np.timedelta64: ...

pandas-stubs/_libs/tslibs/timestamps.pyi

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class Timestamp(datetime, SupportsIndex):
175175
# Mypy complains Forward operator "<inequality op>" is not callable, so ignore misc
176176
# for le, lt ge and gt
177177
@overload # type: ignore[override]
178-
def __le__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc]
178+
def __le__(self, other: datetime | np.datetime64 | Self) -> bool: ...
179179
@overload
180180
def __le__(self, other: DatetimeIndex) -> np_1darray[np.bool]: ...
181181
@overload
@@ -185,7 +185,7 @@ class Timestamp(datetime, SupportsIndex):
185185
@overload
186186
def __le__(self, other: Series[Timestamp]) -> Series[bool]: ...
187187
@overload # type: ignore[override]
188-
def __lt__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc]
188+
def __lt__(self, other: datetime | np.datetime64 | Self) -> bool: ...
189189
@overload
190190
def __lt__(self, other: DatetimeIndex) -> np_1darray[np.bool]: ...
191191
@overload
@@ -195,7 +195,7 @@ class Timestamp(datetime, SupportsIndex):
195195
@overload
196196
def __lt__(self, other: Series[Timestamp]) -> Series[bool]: ...
197197
@overload # type: ignore[override]
198-
def __ge__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc]
198+
def __ge__(self, other: datetime | np.datetime64 | Self) -> bool: ...
199199
@overload
200200
def __ge__(self, other: DatetimeIndex) -> np_1darray[np.bool]: ...
201201
@overload
@@ -205,7 +205,7 @@ class Timestamp(datetime, SupportsIndex):
205205
@overload
206206
def __ge__(self, other: Series[Timestamp]) -> Series[bool]: ...
207207
@overload # type: ignore[override]
208-
def __gt__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc]
208+
def __gt__(self, other: datetime | np.datetime64 | Self) -> bool: ...
209209
@overload
210210
def __gt__(self, other: DatetimeIndex) -> np_1darray[np.bool]: ...
211211
@overload
@@ -231,7 +231,7 @@ class Timestamp(datetime, SupportsIndex):
231231
def __radd__(
232232
self, other: np_ndarray[ShapeT, np.timedelta64]
233233
) -> np_ndarray[ShapeT, np.datetime64]: ...
234-
# TODO: test dt64
234+
# TODO: pandas-dev/pandas-stubs#1432 test dt64
235235
@overload # type: ignore[override]
236236
def __sub__(self, other: datetime | np.datetime64) -> Timedelta: ...
237237
@overload
@@ -243,7 +243,7 @@ class Timestamp(datetime, SupportsIndex):
243243
self, other: np_ndarray[ShapeT, np.timedelta64]
244244
) -> np_ndarray[ShapeT, np.datetime64]: ...
245245
@overload
246-
def __eq__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
246+
def __eq__(self, other: datetime | np.datetime64 | Self) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
247247
@overload
248248
def __eq__(self, other: Series[Timestamp]) -> Series[bool]: ... # type: ignore[overload-overlap]
249249
@overload
@@ -253,7 +253,7 @@ class Timestamp(datetime, SupportsIndex):
253253
@overload
254254
def __eq__(self, other: object) -> Literal[False]: ...
255255
@overload
256-
def __ne__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
256+
def __ne__(self, other: datetime | np.datetime64 | Self) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
257257
@overload
258258
def __ne__(self, other: Series[Timestamp]) -> Series[bool]: ... # type: ignore[overload-overlap]
259259
@overload
@@ -287,15 +287,15 @@ class Timestamp(datetime, SupportsIndex):
287287
@property
288288
def asm8(self) -> np.datetime64: ...
289289
def tz_convert(self, tz: TimeZones) -> Self: ...
290-
# TODO: could return NaT?
290+
# TODO: pandas-dev/pandas-stubs#1432 could return NaT?
291291
def tz_localize(
292292
self,
293293
tz: TimeZones,
294294
ambiguous: _Ambiguous = "raise",
295295
nonexistent: TimestampNonexistent = "raise",
296296
) -> Self: ...
297297
def normalize(self) -> Self: ...
298-
# TODO: round/floor/ceil could return NaT?
298+
# TODO: pandas-dev/pandas-stubs#1432 round/floor/ceil could return NaT?
299299
def round(
300300
self,
301301
freq: str,

pandas-stubs/core/base.pyi

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,15 @@ from pandas._libs.tslibs.timedeltas import Timedelta
2828
from pandas._typing import (
2929
S1,
3030
S2,
31-
ArrayLike,
3231
AxisIndex,
3332
DropKeep,
3433
DTypeLike,
3534
GenericT,
3635
GenericT_co,
3736
Just,
37+
ListLike,
3838
NDFrameT,
3939
Scalar,
40-
SequenceNotStr,
4140
SupportsDType,
4241
np_1darray,
4342
np_ndarray_anyint,
@@ -47,8 +46,6 @@ from pandas._typing import (
4746
)
4847
from pandas.util._decorators import cache_readonly
4948

50-
_ListLike: TypeAlias = ArrayLike | dict[str, np.ndarray] | SequenceNotStr[S1]
51-
5249
class NoNewAttributesMixin:
5350
def __setattr__(self, key: str, value: Any) -> None: ...
5451

@@ -157,16 +154,16 @@ class IndexOpsMixin(OpsMixin, Generic[S1, GenericT_co]):
157154
@overload
158155
def searchsorted(
159156
self,
160-
value: _ListLike,
157+
value: ListLike,
161158
side: Literal["left", "right"] = ...,
162-
sorter: _ListLike | None = ...,
159+
sorter: ListLike | None = None,
163160
) -> np_1darray[np.intp]: ...
164161
@overload
165162
def searchsorted(
166163
self,
167164
value: Scalar,
168165
side: Literal["left", "right"] = ...,
169-
sorter: _ListLike | None = ...,
166+
sorter: ListLike | None = None,
170167
) -> np.intp: ...
171168
def drop_duplicates(self, *, keep: DropKeep = ...) -> Self: ...
172169

0 commit comments

Comments
 (0)