Skip to content

Commit 93a9e11

Browse files
authored
align typing with pandas source (pandas-dev#1219)
* align typing with pandas source * respond to PR comments
1 parent 8607315 commit 93a9e11

25 files changed

+703
-380
lines changed

pandas-stubs/_libs/tslibs/nattype.pyi

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ from datetime import (
44
timedelta,
55
tzinfo as _tzinfo,
66
)
7+
from typing import Literal
78

89
import numpy as np
910
from typing_extensions import (
@@ -13,7 +14,9 @@ from typing_extensions import (
1314

1415
from pandas._libs.tslibs.period import Period
1516
from pandas._typing import (
17+
Frequency,
1618
NpDtype,
19+
TimestampNonexistent,
1720
TimeUnit,
1821
)
1922

@@ -75,11 +78,31 @@ class NaTType:
7578
def now(self, tz: _tzinfo | str | None = ...) -> NaTType: ...
7679
def to_pydatetime(self) -> NaTType: ...
7780
def date(self) -> NaTType: ...
78-
def round(self) -> NaTType: ...
79-
def floor(self) -> NaTType: ...
80-
def ceil(self) -> NaTType: ...
81+
def round(
82+
self,
83+
freq: Frequency,
84+
ambiguous: bool | Literal["raise"] | NaTType = ...,
85+
nonexistent: TimestampNonexistent = ...,
86+
) -> NaTType: ...
87+
def floor(
88+
self,
89+
freq: Frequency,
90+
ambiguous: bool | Literal["raise"] | NaTType = ...,
91+
nonexistent: TimestampNonexistent = ...,
92+
) -> NaTType: ...
93+
def ceil(
94+
self,
95+
freq: Frequency,
96+
ambiguous: bool | Literal["raise"] | NaTType = ...,
97+
nonexistent: TimestampNonexistent = ...,
98+
) -> NaTType: ...
8199
def tz_convert(self) -> NaTType: ...
82-
def tz_localize(self) -> NaTType: ...
100+
def tz_localize(
101+
self,
102+
tz: _tzinfo | str | None,
103+
ambiguous: bool | Literal["raise"] | NaTType = ...,
104+
nonexistent: TimestampNonexistent = ...,
105+
) -> NaTType: ...
83106
def replace(
84107
self,
85108
year: int | None = ...,

pandas-stubs/_libs/tslibs/timestamps.pyi

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,14 @@ from pandas._libs.tslibs import (
4040
Timedelta,
4141
)
4242
from pandas._typing import (
43+
TimestampNonexistent,
4344
TimeUnit,
4445
np_ndarray_bool,
4546
npt,
4647
)
4748

4849
_Ambiguous: TypeAlias = bool | Literal["raise", "NaT"]
49-
_Nonexistent: TypeAlias = (
50-
Literal["raise", "NaT", "shift_backward", "shift_forward"] | Timedelta | timedelta
51-
)
50+
5251
# Repeated from `_typing.pyi` so as to satisfy mixed strict / non-strict paths.
5352
# https://github.com/pandas-dev/pandas-stubs/pull/1151#issuecomment-2715130190
5453
TimeZones: TypeAlias = str | _tzinfo | None | int
@@ -278,27 +277,27 @@ class Timestamp(datetime, SupportsIndex):
278277
self,
279278
tz: TimeZones,
280279
ambiguous: _Ambiguous = ...,
281-
nonexistent: _Nonexistent = ...,
280+
nonexistent: TimestampNonexistent = ...,
282281
) -> Self: ...
283282
def normalize(self) -> Self: ...
284283
# TODO: round/floor/ceil could return NaT?
285284
def round(
286285
self,
287286
freq: str,
288287
ambiguous: _Ambiguous = ...,
289-
nonexistent: _Nonexistent = ...,
288+
nonexistent: TimestampNonexistent = ...,
290289
) -> Self: ...
291290
def floor(
292291
self,
293292
freq: str,
294293
ambiguous: _Ambiguous = ...,
295-
nonexistent: _Nonexistent = ...,
294+
nonexistent: TimestampNonexistent = ...,
296295
) -> Self: ...
297296
def ceil(
298297
self,
299298
freq: str,
300299
ambiguous: _Ambiguous = ...,
301-
nonexistent: _Nonexistent = ...,
300+
nonexistent: TimestampNonexistent = ...,
302301
) -> Self: ...
303302
def day_name(self, locale: str | None = ...) -> str: ...
304303
def month_name(self, locale: str | None = ...) -> str: ...

0 commit comments

Comments
 (0)