Skip to content

Commit bcae446

Browse files
authored
TYP: use annotations in strprime.pyi and timestamps.pyi (#41841)
1 parent dae5c59 commit bcae446

File tree

2 files changed

+37
-48
lines changed

2 files changed

+37
-48
lines changed

pandas/_libs/tslibs/strptime.pyi

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
from typing import Optional
2-
31
import numpy as np
42

53
def array_strptime(
64
values: np.ndarray, # np.ndarray[object]
7-
fmt: Optional[str],
5+
fmt: str | None,
86
exact: bool = True,
9-
errors: str = "raise"
7+
errors: str = "raise",
108
) -> tuple[np.ndarray, np.ndarray]: ...
11-
# first ndarray is M8[ns], second is object ndarray of Optional[tzinfo]
9+
10+
# first ndarray is M8[ns], second is object ndarray of tzinfo | None

pandas/_libs/tslibs/timestamps.pyi

+33-43
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import sys
99
from time import struct_time
1010
from typing import (
1111
ClassVar,
12-
Optional,
1312
Type,
1413
TypeVar,
1514
overload,
@@ -27,10 +26,8 @@ from pandas._libs.tslibs import (
2726

2827
_S = TypeVar("_S")
2928

30-
3129
def integer_op_not_supported(obj) -> None: ...
3230

33-
3431
class Timestamp(datetime):
3532
min: ClassVar[Timestamp]
3633
max: ClassVar[Timestamp]
@@ -41,9 +38,15 @@ class Timestamp(datetime):
4138
# error: "__new__" must return a class instance (got "Union[Timestamp, NaTType]")
4239
def __new__( # type: ignore[misc]
4340
cls: Type[_S],
44-
ts_input: int | np.integer | float | str | _date | datetime | np.datetime64 = ...,
41+
ts_input: int
42+
| np.integer
43+
| float
44+
| str
45+
| _date
46+
| datetime
47+
| np.datetime64 = ...,
4548
freq=...,
46-
tz: str | _tzinfo | None | int= ...,
49+
tz: str | _tzinfo | None | int = ...,
4750
unit=...,
4851
year: int | None = ...,
4952
month: int | None = ...,
@@ -55,7 +58,7 @@ class Timestamp(datetime):
5558
nanosecond: int | None = ...,
5659
tzinfo: _tzinfo | None = ...,
5760
*,
58-
fold: int | None= ...,
61+
fold: int | None = ...,
5962
) -> _S | NaTType: ...
6063

6164
def _set_freq(self, freq: BaseOffset | None) -> None: ...
@@ -75,22 +78,19 @@ class Timestamp(datetime):
7578
@property
7679
def microsecond(self) -> int: ...
7780
@property
78-
def tzinfo(self) -> Optional[_tzinfo]: ...
81+
def tzinfo(self) -> _tzinfo | None: ...
7982
@property
80-
def tz(self) -> Optional[_tzinfo]: ...
81-
83+
def tz(self) -> _tzinfo | None: ...
8284
@property
8385
def fold(self) -> int: ...
84-
8586
@classmethod
86-
def fromtimestamp(cls: Type[_S], t: float, tz: Optional[_tzinfo] = ...) -> _S: ...
87+
def fromtimestamp(cls: Type[_S], t: float, tz: _tzinfo | None = ...) -> _S: ...
8788
@classmethod
8889
def utcfromtimestamp(cls: Type[_S], t: float) -> _S: ...
8990
@classmethod
9091
def today(cls: Type[_S]) -> _S: ...
9192
@classmethod
9293
def fromordinal(cls: Type[_S], n: int) -> _S: ...
93-
9494
if sys.version_info >= (3, 8):
9595
@classmethod
9696
def now(cls: Type[_S], tz: _tzinfo | str | None = ...) -> _S: ...
@@ -101,28 +101,23 @@ class Timestamp(datetime):
101101
@overload
102102
@classmethod
103103
def now(cls, tz: _tzinfo) -> datetime: ...
104-
105104
@classmethod
106105
def utcnow(cls: Type[_S]) -> _S: ...
107106
@classmethod
108-
def combine(cls, date: _date, time: _time, tzinfo: Optional[_tzinfo] = ...) -> datetime: ...
109-
107+
def combine(
108+
cls, date: _date, time: _time, tzinfo: _tzinfo | None = ...
109+
) -> datetime: ...
110110
@classmethod
111111
def fromisoformat(cls: Type[_S], date_string: str) -> _S: ...
112-
113112
def strftime(self, fmt: str) -> str: ...
114113
def __format__(self, fmt: str) -> str: ...
115-
116114
def toordinal(self) -> int: ...
117115
def timetuple(self) -> struct_time: ...
118-
119116
def timestamp(self) -> float: ...
120-
121117
def utctimetuple(self) -> struct_time: ...
122118
def date(self) -> _date: ...
123119
def time(self) -> _time: ...
124120
def timetz(self) -> _time: ...
125-
126121
def replace(
127122
self,
128123
year: int = ...,
@@ -132,26 +127,21 @@ class Timestamp(datetime):
132127
minute: int = ...,
133128
second: int = ...,
134129
microsecond: int = ...,
135-
tzinfo: Optional[_tzinfo] = ...,
130+
tzinfo: _tzinfo | None = ...,
136131
*,
137132
fold: int = ...,
138133
) -> datetime: ...
139-
140134
if sys.version_info >= (3, 8):
141-
def astimezone(self: _S, tz: Optional[_tzinfo] = ...) -> _S: ...
135+
def astimezone(self: _S, tz: _tzinfo | None = ...) -> _S: ...
142136
else:
143-
def astimezone(self, tz: Optional[_tzinfo] = ...) -> datetime: ...
144-
137+
def astimezone(self, tz: _tzinfo | None = ...) -> datetime: ...
145138
def ctime(self) -> str: ...
146139
def isoformat(self, sep: str = ..., timespec: str = ...) -> str: ...
147-
148140
@classmethod
149141
def strptime(cls, date_string: str, format: str) -> datetime: ...
150-
151-
def utcoffset(self) -> Optional[timedelta]: ...
152-
def tzname(self) -> Optional[str]: ...
153-
def dst(self) -> Optional[timedelta]: ...
154-
142+
def utcoffset(self) -> timedelta | None: ...
143+
def tzname(self) -> str | None: ...
144+
def dst(self) -> timedelta | None: ...
155145
def __le__(self, other: datetime) -> bool: ... # type: ignore
156146
def __lt__(self, other: datetime) -> bool: ... # type: ignore
157147
def __ge__(self, other: datetime) -> bool: ... # type: ignore
@@ -166,12 +156,10 @@ class Timestamp(datetime):
166156
def __sub__(self, other: datetime) -> timedelta: ...
167157
@overload
168158
def __sub__(self, other: timedelta) -> datetime: ...
169-
170159
def __hash__(self) -> int: ...
171160
def weekday(self) -> int: ...
172161
def isoweekday(self) -> int: ...
173162
def isocalendar(self) -> tuple[int, int, int]: ...
174-
175163
@property
176164
def is_leap_year(self) -> bool: ...
177165
@property
@@ -186,23 +174,25 @@ class Timestamp(datetime):
186174
def is_quarter_end(self) -> bool: ...
187175
@property
188176
def is_year_end(self) -> bool: ...
189-
190177
def to_pydatetime(self, warn: bool = ...) -> datetime: ...
191178
def to_datetime64(self) -> np.datetime64: ...
192179
def to_period(self, freq) -> Period: ...
193180
def to_julian_date(self) -> np.float64: ...
194-
195181
@property
196182
def asm8(self) -> np.datetime64: ...
197-
198183
def tz_convert(self: _S, tz) -> _S: ...
199-
200184
# TODO: could return NaT?
201-
def tz_localize(self: _S, tz, ambiguous: str = ..., nonexistent: str = ...) -> _S: ...
202-
185+
def tz_localize(
186+
self: _S, tz, ambiguous: str = ..., nonexistent: str = ...
187+
) -> _S: ...
203188
def normalize(self: _S) -> _S: ...
204-
205189
# TODO: round/floor/ceil could return NaT?
206-
def round(self: _S, freq, ambiguous: bool | str = ..., nonexistent: str = ...) -> _S: ...
207-
def floor(self: _S, freq, ambiguous: bool | str = ..., nonexistent: str = ...) -> _S: ...
208-
def ceil(self: _S, freq, ambiguous: bool | str = ..., nonexistent: str = ...) -> _S: ...
190+
def round(
191+
self: _S, freq, ambiguous: bool | str = ..., nonexistent: str = ...
192+
) -> _S: ...
193+
def floor(
194+
self: _S, freq, ambiguous: bool | str = ..., nonexistent: str = ...
195+
) -> _S: ...
196+
def ceil(
197+
self: _S, freq, ambiguous: bool | str = ..., nonexistent: str = ...
198+
) -> _S: ...

0 commit comments

Comments
 (0)