Skip to content

Commit 9f4013b

Browse files
authored
make Timestamp.strptime() return None (#541)
* make Timestamp.strptime() return None * Use Never
1 parent da901f1 commit 9f4013b

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

pandas-stubs/_libs/tslibs/timestamps.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ from pandas.core.series import (
2424
TimestampSeries,
2525
)
2626
from typing_extensions import (
27+
Never,
2728
Self,
2829
TypeAlias,
2930
)
@@ -146,7 +147,7 @@ class Timestamp(datetime):
146147
def ctime(self) -> str: ...
147148
def isoformat(self, sep: str = ..., timespec: str = ...) -> str: ...
148149
@classmethod
149-
def strptime(cls, date_string: str, format: str) -> datetime: ...
150+
def strptime(cls, date_string: Never, format: Never) -> Never: ... # type: ignore[override]
150151
def utcoffset(self) -> timedelta | None: ...
151152
def tzname(self) -> str | None: ...
152153
def dst(self) -> timedelta | None: ...

tests/test_timefuncs.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
from numpy import typing as npt
1414
import pandas as pd
1515
import pytz
16-
from typing_extensions import assert_type
16+
from typing_extensions import (
17+
assert_never,
18+
assert_type,
19+
)
1720

1821
from pandas._libs import NaTType
1922
from pandas._libs.tslibs import BaseOffset
@@ -1122,3 +1125,13 @@ def test_mean_median_std() -> None:
11221125
check(assert_type(s2.mean(), pd.Timestamp), pd.Timestamp)
11231126
check(assert_type(s2.median(), pd.Timestamp), pd.Timestamp)
11241127
check(assert_type(s2.std(), pd.Timedelta), pd.Timedelta)
1128+
1129+
1130+
def test_timestamp_strptime_fails():
1131+
if TYPE_CHECKING_INVALID_USAGE:
1132+
assert_never(
1133+
pd.Timestamp.strptime(
1134+
"2023-02-16", # type: ignore[arg-type] # pyright: ignore[reportGeneralTypeIssues]
1135+
"%Y-%M-%D", # type: ignore[arg-type] # pyright: ignore[reportGeneralTypeIssues]
1136+
)
1137+
)

0 commit comments

Comments
 (0)