Skip to content

Commit 9c03aef

Browse files
Merge branch 'main' into gh1419_index_where
2 parents 96c8a14 + 72138f7 commit 9c03aef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+2498
-1682
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ ci:
33
autofix_prs: false
44
repos:
55
- repo: https://github.com/astral-sh/ruff-pre-commit
6-
rev: v0.13.3
6+
rev: v0.14.1
77
hooks:
88
- id: ruff-check
99
args: [--exit-non-zero-on-fix]

pandas-stubs/_libs/tslibs/period.pyi

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
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
1917
from pandas._libs.tslibs.offsets import BaseOffset
18+
from pandas._libs.tslibs.timedeltas import Timedelta
2019
from pandas._libs.tslibs.timestamps import Timestamp
2120
from pandas._typing import (
21+
PeriodFrequency,
2222
ShapeT,
2323
np_1darray,
2424
np_ndarray,
@@ -63,7 +63,7 @@ class Period(PeriodMixin):
6363
value: (
6464
Period | str | datetime.datetime | datetime.date | Timestamp | None
6565
) = ...,
66-
freq: str | BaseOffset | None = ...,
66+
freq: PeriodFrequency | None = None,
6767
ordinal: int | None = ...,
6868
year: int | None = ...,
6969
month: int | None = ...,
@@ -76,7 +76,7 @@ class Period(PeriodMixin):
7676
@overload
7777
def __sub__(self, other: _PeriodAddSub) -> Period: ...
7878
@overload
79-
def __sub__(self, other: Period) -> BaseOffset: ...
79+
def __sub__(self, other: Self) -> BaseOffset: ...
8080
@overload
8181
def __sub__(self, other: NaTType) -> NaTType: ...
8282
@overload
@@ -91,24 +91,21 @@ class Period(PeriodMixin):
9191
def __add__(self, other: _PeriodAddSub) -> Self: ...
9292
@overload
9393
def __add__(self, other: NaTType) -> NaTType: ...
94-
@overload
95-
def __add__(self, other: Index) -> PeriodIndex: ...
9694
# Ignored due to indecipherable error from mypy:
9795
# Forward operator "__add__" is not callable [misc]
98-
@overload
99-
def __radd__(self, other: _PeriodAddSub) -> Self: ... # type: ignore[misc]
96+
if sys.version_info >= (3, 11):
97+
@overload
98+
def __radd__(self, other: _PeriodAddSub) -> Self: ...
99+
else:
100+
@overload
101+
def __radd__(self, other: _PeriodAddSub) -> Self: ... # type: ignore[misc]
102+
100103
@overload
101104
def __radd__(self, other: NaTType) -> NaTType: ...
102-
# Real signature is -> PeriodIndex, but conflicts with Index.__add__
103-
# Changing Index is very hard due to Index inheritance
104-
# Signatures of "__radd__" of "Period" and "__add__" of "Index"
105-
# are unsafely overlapping
106-
@overload
107-
def __radd__(self, other: Index) -> PeriodIndex: ...
108105
# ignore[misc] here because we know all other comparisons
109106
# are False, so we use Literal[False]
110107
@overload
111-
def __eq__(self, other: Period) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
108+
def __eq__(self, other: Self) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
112109
@overload
113110
def __eq__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
114111
@overload
@@ -118,7 +115,7 @@ class Period(PeriodMixin):
118115
@overload
119116
def __eq__(self, other: object) -> Literal[False]: ...
120117
@overload
121-
def __ge__(self, other: Period) -> bool: ...
118+
def __ge__(self, other: Self) -> bool: ...
122119
@overload
123120
def __ge__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
124121
@overload
@@ -130,7 +127,7 @@ class Period(PeriodMixin):
130127
self, other: np_ndarray[ShapeT, np.object_]
131128
) -> np_ndarray[ShapeT, np.bool]: ...
132129
@overload
133-
def __gt__(self, other: Period) -> bool: ...
130+
def __gt__(self, other: Self) -> bool: ...
134131
@overload
135132
def __gt__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
136133
@overload
@@ -142,7 +139,7 @@ class Period(PeriodMixin):
142139
self, other: np_ndarray[ShapeT, np.object_]
143140
) -> np_ndarray[ShapeT, np.bool]: ...
144141
@overload
145-
def __le__(self, other: Period) -> bool: ...
142+
def __le__(self, other: Self) -> bool: ...
146143
@overload
147144
def __le__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
148145
@overload
@@ -154,7 +151,7 @@ class Period(PeriodMixin):
154151
self, other: np_ndarray[ShapeT, np.object_]
155152
) -> np_ndarray[ShapeT, np.bool]: ...
156153
@overload
157-
def __lt__(self, other: Period) -> bool: ...
154+
def __lt__(self, other: Self) -> bool: ...
158155
@overload
159156
def __lt__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
160157
@overload
@@ -168,7 +165,7 @@ class Period(PeriodMixin):
168165
# ignore[misc] here because we know all other comparisons
169166
# are False, so we use Literal[False]
170167
@overload
171-
def __ne__(self, other: Period) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
168+
def __ne__(self, other: Self) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
172169
@overload
173170
def __ne__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
174171
@overload
@@ -223,12 +220,12 @@ class Period(PeriodMixin):
223220
def day_of_year(self) -> int: ...
224221
@property
225222
def day_of_week(self) -> int: ...
226-
def asfreq(self, freq: str | BaseOffset, how: _PeriodFreqHow = "end") -> Period: ...
223+
def asfreq(self, freq: PeriodFrequency, how: _PeriodFreqHow = "end") -> Period: ...
227224
@classmethod
228-
def now(cls, freq: str | BaseOffset = ...) -> Period: ...
225+
def now(cls, freq: PeriodFrequency | None = None) -> Period: ...
229226
def strftime(self, fmt: str) -> str: ...
230227
def to_timestamp(
231228
self,
232-
freq: str | BaseOffset | None = ...,
229+
freq: PeriodFrequency | None = None,
233230
how: _PeriodToTimestampHow = "S",
234231
) -> Timestamp: ...

pandas-stubs/_libs/tslibs/timedeltas.pyi

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,24 @@ 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 numpy import typing as npt
17+
from pandas.core.indexes.base import Index
18+
from pandas.core.indexes.datetimes import DatetimeIndex
19+
from pandas.core.indexes.period import PeriodIndex
20+
from pandas.core.indexes.timedeltas import TimedeltaIndex
21+
from pandas.core.series import Series
2422
from typing_extensions import Self
2523

26-
from pandas._libs.tslibs import (
27-
BaseOffset,
28-
NaTType,
29-
)
24+
from pandas._libs.tslibs import NaTType
3025
from pandas._libs.tslibs.period import Period
3126
from pandas._libs.tslibs.timestamps import Timestamp
3227
from pandas._typing import (
28+
Frequency,
29+
Just,
3330
ShapeT,
3431
TimeUnit,
3532
np_1darray,
3633
np_ndarray,
37-
npt,
3834
)
3935

4036
class Components(NamedTuple):
@@ -130,10 +126,10 @@ class Timedelta(timedelta):
130126
def to_timedelta64(self) -> np.timedelta64: ...
131127
@property
132128
def asm8(self) -> np.timedelta64: ...
133-
# TODO: round/floor/ceil could return NaT?
134-
def round(self, freq: str | BaseOffset) -> Self: ...
135-
def floor(self, freq: str | BaseOffset) -> Self: ...
136-
def ceil(self, freq: str | BaseOffset) -> Self: ...
129+
# TODO: pandas-dev/pandas-stubs#1432 round/floor/ceil could return NaT?
130+
def round(self, freq: Frequency) -> Self: ...
131+
def floor(self, freq: Frequency) -> Self: ...
132+
def ceil(self, freq: Frequency) -> Self: ...
137133
@property
138134
def resolution_string(self) -> str: ...
139135
# Override due to more types supported than timedelta
@@ -173,17 +169,17 @@ class Timedelta(timedelta):
173169
) -> np_ndarray[ShapeT, np.datetime64]: ...
174170
# Override due to more types supported than timedelta
175171
@overload # type: ignore[override]
176-
def __sub__(self, other: timedelta | Timedelta | np.timedelta64) -> Self: ...
172+
def __sub__(self, other: timedelta | np.timedelta64 | Self) -> Self: ...
177173
@overload
178174
def __sub__(self, other: NaTType) -> NaTType: ...
179175
@overload
180176
def __sub__(
181177
self, other: np_ndarray[ShapeT, np.timedelta64]
182178
) -> np_ndarray[ShapeT, np.timedelta64]: ...
183179
@overload
184-
def __sub__(self, other: pd.TimedeltaIndex) -> TimedeltaIndex: ...
180+
def __sub__(self, other: TimedeltaIndex) -> TimedeltaIndex: ...
185181
@overload
186-
def __rsub__(self, other: timedelta | Timedelta | np.timedelta64) -> Self: ...
182+
def __rsub__(self, other: timedelta | np.timedelta64 | Self) -> Self: ...
187183
@overload
188184
def __rsub__(self, other: datetime | Timestamp | np.datetime64) -> Timestamp: ... # type: ignore[misc]
189185
@overload
@@ -203,27 +199,27 @@ class Timedelta(timedelta):
203199
self, other: np_ndarray[ShapeT, np.timedelta64]
204200
) -> np_ndarray[ShapeT, np.timedelta64]: ...
205201
@overload
206-
def __rsub__(self, other: pd.TimedeltaIndex) -> pd.TimedeltaIndex: ...
202+
def __rsub__(self, other: TimedeltaIndex) -> TimedeltaIndex: ...
207203
def __neg__(self) -> Self: ...
208204
def __pos__(self) -> Self: ...
209205
def __abs__(self) -> Self: ...
210206
# Override due to more types supported than timedelta
211207
@overload # type: ignore[override]
212-
def __mul__(self, other: float) -> Self: ...
208+
def __mul__(self, other: Just[float] | Just[int]) -> Self: ...
213209
@overload
214210
def __mul__(
215211
self, other: np_ndarray[ShapeT, np.bool_ | np.integer | np.floating]
216212
) -> np_ndarray[ShapeT, np.timedelta64]: ...
217213
@overload
218-
def __rmul__(self, other: float) -> Self: ...
214+
def __rmul__(self, other: Just[float] | Just[int]) -> Self: ...
219215
@overload
220216
def __rmul__(
221217
self, other: np_ndarray[ShapeT, np.bool_ | np.integer | np.floating]
222218
) -> np_ndarray[ShapeT, np.timedelta64]: ...
223219
# Override due to more types supported than timedelta
224220
# error: Signature of "__floordiv__" incompatible with supertype "timedelta"
225221
@overload # type: ignore[override]
226-
def __floordiv__(self, other: timedelta | Timedelta | np.timedelta64) -> int: ...
222+
def __floordiv__(self, other: timedelta | np.timedelta64 | Self) -> int: ...
227223
@overload
228224
def __floordiv__(self, other: float) -> Self: ...
229225
@overload
@@ -254,27 +250,29 @@ class Timedelta(timedelta):
254250
) -> np_ndarray[ShapeT, np.int_]: ...
255251
# Override due to more types supported than timedelta
256252
@overload # type: ignore[override]
257-
def __truediv__(self, other: timedelta | Timedelta | NaTType) -> float: ...
253+
# pyrefly: ignore[bad-override]
254+
def __truediv__(self, other: Just[int] | Just[float]) -> Self: ...
258255
@overload
259-
def __truediv__(self, other: float) -> Self: ...
256+
def __truediv__(self, other: Self | NaTType) -> float: ...
260257
@overload
261258
def __truediv__(
262259
self, other: np_ndarray[ShapeT, np.integer | np.floating]
263260
) -> np_ndarray[ShapeT, np.timedelta64]: ...
264261
@overload
265-
def __truediv__(self, other: Series[Timedelta]) -> Series[float]: ...
266-
@overload
267-
def __truediv__(self, other: Series[int]) -> Series[Timedelta]: ...
262+
def __truediv__(
263+
self, other: np_ndarray[ShapeT, np.timedelta64]
264+
) -> np_ndarray[ShapeT, np.floating]: ...
268265
@overload
269-
def __truediv__(self, other: Series[float]) -> Series[Timedelta]: ...
266+
def __rtruediv__(self, other: Self | NaTType) -> float: ...
270267
@overload
271-
def __truediv__(self, other: Index[int] | Index[float]) -> TimedeltaIndex: ...
272-
def __rtruediv__(self, other: timedelta | Timedelta | NaTType) -> float: ...
268+
def __rtruediv__(
269+
self, other: np_ndarray[ShapeT, np.timedelta64]
270+
) -> np_ndarray[ShapeT, np.floating]: ...
273271
# Override due to more types supported than timedelta
274272
@overload
275-
def __eq__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
273+
def __eq__(self, other: timedelta | np.timedelta64 | Self) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
276274
@overload
277-
def __eq__(self, other: Series[pd.Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
275+
def __eq__(self, other: Series[Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
278276
@overload
279277
def __eq__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
280278
@overload
@@ -285,9 +283,9 @@ class Timedelta(timedelta):
285283
def __eq__(self, other: object) -> Literal[False]: ...
286284
# Override due to more types supported than timedelta
287285
@overload
288-
def __ne__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
286+
def __ne__(self, other: timedelta | np.timedelta64 | Self) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
289287
@overload
290-
def __ne__(self, other: Series[pd.Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
288+
def __ne__(self, other: Series[Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
291289
@overload
292290
def __ne__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
293291
@overload
@@ -314,52 +312,50 @@ class Timedelta(timedelta):
314312
self, other: Series[int] | Series[float] | Series[Timedelta]
315313
) -> Series[Timedelta]: ...
316314
def __divmod__(self, other: timedelta) -> tuple[int, Timedelta]: ...
317-
# Mypy complains Forward operator "<inequality op>" is not callable, so ignore misc
318-
# for le, lt ge and gt
319315
# Override due to more types supported than timedelta
320316
@overload # type: ignore[override]
321-
def __le__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
317+
def __le__(self, other: timedelta | np.timedelta64 | Self) -> bool: ...
322318
@overload
323319
def __le__(self, other: TimedeltaIndex) -> np_1darray[np.bool]: ...
324320
@overload
325321
def __le__(
326322
self, other: np_ndarray[ShapeT, np.timedelta64]
327323
) -> np_ndarray[ShapeT, np.bool_]: ...
328324
@overload
329-
def __le__(self, other: Series[pd.Timedelta]) -> Series[bool]: ...
325+
def __le__(self, other: Series[Timedelta]) -> Series[bool]: ...
330326
# Override due to more types supported than timedelta
331327
@overload # type: ignore[override]
332-
def __lt__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
328+
def __lt__(self, other: timedelta | np.timedelta64 | Self) -> bool: ...
333329
@overload
334330
def __lt__(self, other: TimedeltaIndex) -> np_1darray[np.bool]: ...
335331
@overload
336332
def __lt__(
337333
self, other: np_ndarray[ShapeT, np.timedelta64]
338334
) -> np_ndarray[ShapeT, np.bool_]: ...
339335
@overload
340-
def __lt__(self, other: Series[pd.Timedelta]) -> Series[bool]: ...
336+
def __lt__(self, other: Series[Timedelta]) -> Series[bool]: ...
341337
# Override due to more types supported than timedelta
342338
@overload # type: ignore[override]
343-
def __ge__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
339+
def __ge__(self, other: timedelta | np.timedelta64 | Self) -> bool: ...
344340
@overload
345341
def __ge__(self, other: TimedeltaIndex) -> np_1darray[np.bool]: ...
346342
@overload
347343
def __ge__(
348344
self, other: np_ndarray[ShapeT, np.timedelta64]
349345
) -> np_ndarray[ShapeT, np.bool_]: ...
350346
@overload
351-
def __ge__(self, other: Series[pd.Timedelta]) -> Series[bool]: ...
347+
def __ge__(self, other: Series[Timedelta]) -> Series[bool]: ...
352348
# Override due to more types supported than timedelta
353349
@overload # type: ignore[override]
354-
def __gt__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
350+
def __gt__(self, other: timedelta | np.timedelta64 | Self) -> bool: ...
355351
@overload
356352
def __gt__(self, other: TimedeltaIndex) -> np_1darray[np.bool]: ...
357353
@overload
358354
def __gt__(
359355
self, other: np_ndarray[ShapeT, np.timedelta64]
360356
) -> np_ndarray[ShapeT, np.bool_]: ...
361357
@overload
362-
def __gt__(self, other: Series[pd.Timedelta]) -> Series[bool]: ...
358+
def __gt__(self, other: Series[Timedelta]) -> Series[bool]: ...
363359
def __hash__(self) -> int: ...
364360
def isoformat(self) -> str: ...
365361
def to_numpy(self) -> np.timedelta64: ...

0 commit comments

Comments
 (0)