Skip to content

Commit da901f1

Browse files
authored
Enable Y019, Y037, and Y041 (#540)
* Enable Y037 * and Y019 * and Y041
1 parent 0fd68ab commit da901f1

23 files changed

+285
-335
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ repos:
3030
- flake8-pyi==23.1.2
3131
types: [pyi]
3232
args: [
33-
--ignore=E301 E302 E305 E402 E501 E701 E704 F401 F811 W503 Y019 Y037 Y041 Y042,
33+
--ignore=E301 E302 E305 E402 E501 E701 E704 F401 F811 W503 Y042,
3434
# TypeVars in private files are already private
3535
--per-file-ignores=_*.pyi:Y001
3636
]

pandas-stubs/_libs/interval.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
148148
@overload
149149
def __rmul__(self: Interval[Timedelta], y: float) -> Interval[Timedelta]: ...
150150
@overload
151-
def __truediv__(self: Interval[int], y: int | float) -> Interval[float]: ...
151+
def __truediv__(self: Interval[int], y: float) -> Interval[float]: ...
152152
@overload
153153
def __truediv__(self: Interval[float], y: float) -> Interval[float]: ...
154154
@overload

pandas-stubs/_libs/tslibs/nattype.pyi

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ from datetime import (
33
timedelta,
44
tzinfo as _tzinfo,
55
)
6-
from typing import Union
76

87
import numpy as np
98
from typing_extensions import TypeAlias
@@ -14,9 +13,9 @@ NaT: NaTType
1413
iNaT: int
1514
nat_strings: set[str]
1615

17-
_NaTComparisonTypes: TypeAlias = Union[
18-
datetime, timedelta, Period, np.datetime64, np.timedelta64
19-
]
16+
_NaTComparisonTypes: TypeAlias = (
17+
datetime | timedelta | Period | np.datetime64 | np.timedelta64
18+
)
2019

2120
class _NatComparison:
2221
def __call__(self, other: _NaTComparisonTypes) -> bool: ...

pandas-stubs/_libs/tslibs/offsets.pyi

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ from typing import (
1414

1515
import numpy as np
1616
from pandas.core.indexes.datetimes import DatetimeIndex
17+
from typing_extensions import Self
1718

1819
from pandas._typing import npt
1920

2021
from pandas.tseries.holiday import AbstractHolidayCalendar
2122

2223
from .timedeltas import Timedelta
2324

24-
_BaseOffsetT = TypeVar("_BaseOffsetT", bound=BaseOffset)
2525
_DatetimeT = TypeVar("_DatetimeT", bound=date)
2626
_TimedeltaT = TypeVar("_TimedeltaT", bound=timedelta)
2727

@@ -42,24 +42,24 @@ class BaseOffset:
4242
@overload
4343
def __add__(self, other: npt.NDArray[np.object_]) -> npt.NDArray[np.object_]: ...
4444
@overload
45-
def __add__(self: _BaseOffsetT, other: BaseOffset) -> _BaseOffsetT: ...
45+
def __add__(self, other: BaseOffset) -> Self: ...
4646
@overload
4747
def __add__(self, other: _DatetimeT) -> _DatetimeT: ...
4848
@overload
4949
def __add__(self, other: _TimedeltaT) -> _TimedeltaT: ...
5050
@overload
5151
def __radd__(self, other: npt.NDArray[np.object_]) -> npt.NDArray[np.object_]: ...
5252
@overload
53-
def __radd__(self: _BaseOffsetT, other: BaseOffset) -> _BaseOffsetT: ...
53+
def __radd__(self, other: BaseOffset) -> Self: ...
5454
@overload
5555
def __radd__(self, other: _DatetimeT) -> _DatetimeT: ...
5656
@overload
5757
def __radd__(self, other: _TimedeltaT) -> _TimedeltaT: ...
58-
def __sub__(self: _BaseOffsetT, other: BaseOffset) -> _BaseOffsetT: ...
58+
def __sub__(self, other: BaseOffset) -> Self: ...
5959
@overload
6060
def __rsub__(self, other: npt.NDArray[np.object_]) -> npt.NDArray[np.object_]: ...
6161
@overload
62-
def __rsub__(self: _BaseOffsetT, other: BaseOffset) -> _BaseOffsetT: ...
62+
def __rsub__(self, other: BaseOffset) -> Self: ...
6363
@overload
6464
def __rsub__(self, other: _DatetimeT) -> _DatetimeT: ...
6565
@overload
@@ -68,13 +68,13 @@ class BaseOffset:
6868
@overload
6969
def __mul__(self, other: np.ndarray) -> np.ndarray: ...
7070
@overload
71-
def __mul__(self: _BaseOffsetT, other: int) -> _BaseOffsetT: ...
71+
def __mul__(self, other: int) -> Self: ...
7272
@overload
7373
def __rmul__(self, other: np.ndarray) -> np.ndarray: ...
7474
@overload
75-
def __rmul__(self: _BaseOffsetT, other: int) -> _BaseOffsetT: ...
76-
def __neg__(self: _BaseOffsetT) -> _BaseOffsetT: ...
77-
def copy(self: _BaseOffsetT) -> _BaseOffsetT: ...
75+
def __rmul__(self, other: int) -> Self: ...
76+
def __neg__(self) -> Self: ...
77+
def copy(self) -> Self: ...
7878
@property
7979
def name(self) -> str: ...
8080
@property

pandas-stubs/_libs/tslibs/period.pyi

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import datetime
22
from typing import (
33
Literal,
4-
Union,
54
overload,
65
)
76

@@ -29,9 +28,9 @@ class IncompatibleFrequency(ValueError): ...
2928

3029
from pandas._libs.tslibs.offsets import BaseOffset
3130

32-
_PeriodAddSub: TypeAlias = Union[
33-
Timedelta, datetime.timedelta, np.timedelta64, np.int64, int, BaseOffset
34-
]
31+
_PeriodAddSub: TypeAlias = (
32+
Timedelta | datetime.timedelta | np.timedelta64 | np.int64 | int | BaseOffset
33+
)
3534

3635
_PeriodFreqHow: TypeAlias = Literal[
3736
"S",
@@ -40,9 +39,9 @@ _PeriodFreqHow: TypeAlias = Literal[
4039
"end",
4140
]
4241

43-
_PeriodToTimestampHow: TypeAlias = Union[
44-
_PeriodFreqHow,
45-
Literal[
42+
_PeriodToTimestampHow: TypeAlias = (
43+
_PeriodFreqHow
44+
| Literal[
4645
"Start",
4746
"Finish",
4847
"Begin",
@@ -51,8 +50,8 @@ _PeriodToTimestampHow: TypeAlias = Union[
5150
"e",
5251
"finish",
5352
"begin",
54-
],
55-
]
53+
]
54+
)
5655

5756
class PeriodMixin:
5857
@property

pandas-stubs/_libs/tslibs/timedeltas.pyi

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ from typing import (
44
ClassVar,
55
Literal,
66
NamedTuple,
7-
TypeVar,
8-
Union,
97
overload,
108
)
119

@@ -23,7 +21,10 @@ from pandas.core.series import (
2321
TimedeltaSeries,
2422
TimestampSeries,
2523
)
26-
from typing_extensions import TypeAlias
24+
from typing_extensions import (
25+
Self,
26+
TypeAlias,
27+
)
2728

2829
from pandas._libs.tslibs import (
2930
BaseOffset,
@@ -91,24 +92,22 @@ TimeDeltaUnitChoices: TypeAlias = Literal[
9192
"n",
9293
]
9394

94-
UnitChoices: TypeAlias = Union[
95-
TimeDeltaUnitChoices,
96-
Literal[
95+
UnitChoices: TypeAlias = (
96+
TimeDeltaUnitChoices
97+
| Literal[
9798
"Y",
9899
"y",
99100
"M",
100-
],
101-
]
102-
103-
_S = TypeVar("_S", bound=timedelta)
101+
]
102+
)
104103

105104
class Timedelta(timedelta):
106105
min: ClassVar[Timedelta]
107106
max: ClassVar[Timedelta]
108107
resolution: ClassVar[Timedelta]
109108
value: int
110109
def __new__(
111-
cls: type[_S],
110+
cls,
112111
value: str | int | Timedelta | timedelta | np.timedelta64 = ...,
113112
unit: TimeDeltaUnitChoices = ...,
114113
*,
@@ -119,7 +118,7 @@ class Timedelta(timedelta):
119118
minutes: float | np.integer | np.floating = ...,
120119
hours: float | np.integer | np.floating = ...,
121120
weeks: float | np.integer | np.floating = ...,
122-
) -> _S: ...
121+
) -> Self: ...
123122
# GH 46171
124123
# While Timedelta can return pd.NaT, having the constructor return
125124
# a Union with NaTType makes things awkward for users of pandas
@@ -137,9 +136,9 @@ class Timedelta(timedelta):
137136
@property
138137
def asm8(self) -> np.timedelta64: ...
139138
# TODO: round/floor/ceil could return NaT?
140-
def round(self: _S, freq: str | BaseOffset) -> _S: ...
141-
def floor(self: _S, freq: str | BaseOffset) -> _S: ...
142-
def ceil(self: _S, freq: str | BaseOffset) -> _S: ...
139+
def round(self, freq: str | BaseOffset) -> Self: ...
140+
def floor(self, freq: str | BaseOffset) -> Self: ...
141+
def ceil(self, freq: str | BaseOffset) -> Self: ...
143142
@property
144143
def resolution_string(self) -> str: ...
145144
# Override due to more types supported than dt.timedelta

pandas-stubs/_libs/tslibs/timestamps.pyi

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ from time import struct_time
99
from typing import (
1010
ClassVar,
1111
Literal,
12-
TypeVar,
13-
Union,
1412
overload,
1513
)
1614

@@ -25,7 +23,10 @@ from pandas.core.series import (
2523
TimedeltaSeries,
2624
TimestampSeries,
2725
)
28-
from typing_extensions import TypeAlias
26+
from typing_extensions import (
27+
Self,
28+
TypeAlias,
29+
)
2930

3031
from pandas._libs.tslibs import (
3132
BaseOffset,
@@ -38,11 +39,10 @@ from pandas._typing import (
3839
npt,
3940
)
4041

41-
_DatetimeT = TypeVar("_DatetimeT", bound=datetime)
42-
_Ambiguous: TypeAlias = Union[bool, Literal["raise", "NaT"]]
43-
_Nonexistent: TypeAlias = Union[
44-
Literal["raise", "NaT", "shift_backward", "shift_forward"], Timedelta, timedelta
45-
]
42+
_Ambiguous: TypeAlias = bool | Literal["raise", "NaT"]
43+
_Nonexistent: TypeAlias = (
44+
Literal["raise", "NaT", "shift_backward", "shift_forward"] | Timedelta | timedelta
45+
)
4646

4747
class Timestamp(datetime):
4848
min: ClassVar[Timestamp]
@@ -51,7 +51,7 @@ class Timestamp(datetime):
5151
resolution: ClassVar[Timedelta]
5252
value: int
5353
def __new__(
54-
cls: type[_DatetimeT],
54+
cls,
5555
ts_input: np.integer | float | str | _date | datetime | np.datetime64 = ...,
5656
# Freq is deprecated but is left in to allow code like Timestamp(2000,1,1)
5757
# Removing it would make the other arguments position only
@@ -69,7 +69,7 @@ class Timestamp(datetime):
6969
tzinfo: _tzinfo | None = ...,
7070
*,
7171
fold: Literal[0, 1] | None = ...,
72-
) -> _DatetimeT: ...
72+
) -> Self: ...
7373
# GH 46171
7474
# While Timestamp can return pd.NaT, having the constructor return
7575
# a Union with NaTType makes things awkward for users of pandas
@@ -96,30 +96,28 @@ class Timestamp(datetime):
9696
@property
9797
def fold(self) -> int: ...
9898
@classmethod
99-
def fromtimestamp(
100-
cls: type[_DatetimeT], t: float, tz: _tzinfo | str | None = ...
101-
) -> _DatetimeT: ...
99+
def fromtimestamp(cls, t: float, tz: _tzinfo | str | None = ...) -> Self: ...
102100
@classmethod
103-
def utcfromtimestamp(cls: type[_DatetimeT], ts: float) -> _DatetimeT: ...
101+
def utcfromtimestamp(cls, ts: float) -> Self: ...
104102
@classmethod
105-
def today(cls: type[_DatetimeT], tz: _tzinfo | str | None = ...) -> _DatetimeT: ...
103+
def today(cls, tz: _tzinfo | str | None = ...) -> Self: ...
106104
@classmethod
107105
def fromordinal(
108-
cls: type[_DatetimeT],
106+
cls,
109107
ordinal: int,
110108
# freq produces a FutureWarning about being deprecated in a future version
111109
freq: None = ...,
112110
tz: _tzinfo | str | None = ...,
113-
) -> _DatetimeT: ...
111+
) -> Self: ...
114112
@classmethod
115-
def now(cls: type[_DatetimeT], tz: _tzinfo | str | None = ...) -> _DatetimeT: ...
113+
def now(cls, tz: _tzinfo | str | None = ...) -> Self: ...
116114
@classmethod
117-
def utcnow(cls: type[_DatetimeT]) -> _DatetimeT: ...
115+
def utcnow(cls) -> Self: ...
118116
# error: Signature of "combine" incompatible with supertype "datetime"
119117
@classmethod
120118
def combine(cls, date: _date, time: _time) -> datetime: ... # type: ignore[override]
121119
@classmethod
122-
def fromisoformat(cls: type[_DatetimeT], date_string: str) -> _DatetimeT: ...
120+
def fromisoformat(cls, date_string: str) -> Self: ...
123121
def strftime(self, format: str) -> str: ...
124122
def __format__(self, fmt: str) -> str: ...
125123
def toordinal(self) -> int: ...
@@ -144,7 +142,7 @@ class Timestamp(datetime):
144142
tzinfo: _tzinfo | None = ...,
145143
fold: Literal[0, 1] | None = ...,
146144
) -> Timestamp: ...
147-
def astimezone(self: _DatetimeT, tz: _tzinfo | None = ...) -> _DatetimeT: ...
145+
def astimezone(self, tz: _tzinfo | None = ...) -> Self: ...
148146
def ctime(self) -> str: ...
149147
def isoformat(self, sep: str = ..., timespec: str = ...) -> str: ...
150148
@classmethod
@@ -184,15 +182,13 @@ class Timestamp(datetime):
184182
self, other: npt.NDArray[np.timedelta64]
185183
) -> npt.NDArray[np.datetime64]: ...
186184
@overload
187-
def __add__(
188-
self: _DatetimeT, other: timedelta | np.timedelta64 | Tick
189-
) -> _DatetimeT: ...
185+
def __add__(self, other: timedelta | np.timedelta64 | Tick) -> Self: ...
190186
@overload
191187
def __add__(self, other: TimedeltaSeries) -> TimestampSeries: ...
192188
@overload
193189
def __add__(self, other: TimedeltaIndex) -> DatetimeIndex: ...
194190
@overload
195-
def __radd__(self: _DatetimeT, other: timedelta) -> _DatetimeT: ...
191+
def __radd__(self, other: timedelta) -> Self: ...
196192
@overload
197193
def __radd__(self, other: TimedeltaIndex) -> DatetimeIndex: ...
198194
@overload
@@ -203,9 +199,7 @@ class Timestamp(datetime):
203199
@overload # type: ignore[override]
204200
def __sub__(self, other: Timestamp | datetime | np.datetime64) -> Timedelta: ...
205201
@overload
206-
def __sub__(
207-
self: _DatetimeT, other: timedelta | np.timedelta64 | Tick
208-
) -> _DatetimeT: ...
202+
def __sub__(self, other: timedelta | np.timedelta64 | Tick) -> Self: ...
209203
@overload
210204
def __sub__(self, other: TimedeltaIndex) -> DatetimeIndex: ...
211205
@overload
@@ -253,34 +247,34 @@ class Timestamp(datetime):
253247
def to_julian_date(self) -> np.float64: ...
254248
@property
255249
def asm8(self) -> np.datetime64: ...
256-
def tz_convert(self: _DatetimeT, tz: _tzinfo | str | None) -> _DatetimeT: ...
250+
def tz_convert(self, tz: _tzinfo | str | None) -> Self: ...
257251
# TODO: could return NaT?
258252
def tz_localize(
259-
self: _DatetimeT,
253+
self,
260254
tz: _tzinfo | str | None,
261255
ambiguous: _Ambiguous = ...,
262256
nonexistent: _Nonexistent = ...,
263-
) -> _DatetimeT: ...
264-
def normalize(self: _DatetimeT) -> _DatetimeT: ...
257+
) -> Self: ...
258+
def normalize(self) -> Self: ...
265259
# TODO: round/floor/ceil could return NaT?
266260
def round(
267-
self: _DatetimeT,
261+
self,
268262
freq: str,
269263
ambiguous: _Ambiguous = ...,
270264
nonexistent: _Nonexistent = ...,
271-
) -> _DatetimeT: ...
265+
) -> Self: ...
272266
def floor(
273-
self: _DatetimeT,
267+
self,
274268
freq: str,
275269
ambiguous: _Ambiguous = ...,
276270
nonexistent: _Nonexistent = ...,
277-
) -> _DatetimeT: ...
271+
) -> Self: ...
278272
def ceil(
279-
self: _DatetimeT,
273+
self,
280274
freq: str,
281275
ambiguous: _Ambiguous = ...,
282276
nonexistent: _Nonexistent = ...,
283-
) -> _DatetimeT: ...
277+
) -> Self: ...
284278
def day_name(self, locale: str | None = ...) -> str: ...
285279
def month_name(self, locale: str | None = ...) -> str: ...
286280
@property

0 commit comments

Comments
 (0)