diff --git a/pandas-stubs/_libs/tslibs/timestamps.pyi b/pandas-stubs/_libs/tslibs/timestamps.pyi index 78487c209..1e000513c 100644 --- a/pandas-stubs/_libs/tslibs/timestamps.pyi +++ b/pandas-stubs/_libs/tslibs/timestamps.pyi @@ -24,6 +24,7 @@ from pandas.core.series import ( TimestampSeries, ) from typing_extensions import ( + Never, Self, TypeAlias, ) @@ -146,7 +147,7 @@ class Timestamp(datetime): def ctime(self) -> str: ... def isoformat(self, sep: str = ..., timespec: str = ...) -> str: ... @classmethod - def strptime(cls, date_string: str, format: str) -> datetime: ... + def strptime(cls, date_string: Never, format: Never) -> Never: ... # type: ignore[override] def utcoffset(self) -> timedelta | None: ... def tzname(self) -> str | None: ... def dst(self) -> timedelta | None: ... diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index a7eae3238..8ed724666 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -13,7 +13,10 @@ from numpy import typing as npt import pandas as pd import pytz -from typing_extensions import assert_type +from typing_extensions import ( + assert_never, + assert_type, +) from pandas._libs import NaTType from pandas._libs.tslibs import BaseOffset @@ -1122,3 +1125,13 @@ def test_mean_median_std() -> None: check(assert_type(s2.mean(), pd.Timestamp), pd.Timestamp) check(assert_type(s2.median(), pd.Timestamp), pd.Timestamp) check(assert_type(s2.std(), pd.Timedelta), pd.Timedelta) + + +def test_timestamp_strptime_fails(): + if TYPE_CHECKING_INVALID_USAGE: + assert_never( + pd.Timestamp.strptime( + "2023-02-16", # type: ignore[arg-type] # pyright: ignore[reportGeneralTypeIssues] + "%Y-%M-%D", # type: ignore[arg-type] # pyright: ignore[reportGeneralTypeIssues] + ) + )