From a7cfc496a57d59716019b1eb43bb066b7d46bcbd Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Sat, 16 Jul 2022 13:41:42 -0700 Subject: [PATCH 1/5] TYP: Update timestamps.pyi --- pandas/_libs/tslibs/timestamps.pyi | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/pandas/_libs/tslibs/timestamps.pyi b/pandas/_libs/tslibs/timestamps.pyi index f6a62688fc72d..ea4c8ed5c6836 100644 --- a/pandas/_libs/tslibs/timestamps.pyi +++ b/pandas/_libs/tslibs/timestamps.pyi @@ -59,10 +59,6 @@ class Timestamp(datetime): # While Timestamp can return pd.NaT, having the constructor return # a Union with NaTType makes things awkward for users of pandas def _set_freq(self, freq: BaseOffset | None) -> None: ... - @classmethod - def _from_value_and_reso( - cls, value: int, reso: int, tz: _tzinfo | None - ) -> Timestamp: ... @property def year(self) -> int: ... @property @@ -85,10 +81,10 @@ class Timestamp(datetime): def fold(self) -> int: ... @classmethod def fromtimestamp( - cls: type[_DatetimeT], t: float, tz: _tzinfo | None = ... + cls: type[_DatetimeT], ts: float, tz: _tzinfo | None = ... ) -> _DatetimeT: ... @classmethod - def utcfromtimestamp(cls: type[_DatetimeT], t: float) -> _DatetimeT: ... + def utcfromtimestamp(cls: type[_DatetimeT], ts: float) -> _DatetimeT: ... @classmethod def today(cls: type[_DatetimeT], tz: _tzinfo | str | None = ...) -> _DatetimeT: ... @classmethod @@ -120,17 +116,18 @@ class Timestamp(datetime): def timetz(self) -> _time: ... def replace( self: _DatetimeT, - year: int = ..., - month: int = ..., - day: int = ..., - hour: int = ..., - minute: int = ..., - second: int = ..., - microsecond: int = ..., + year: int | None = ..., + month: int | None = ..., + day: int | None = ..., + hour: int | None = ..., + minute: int | None = ..., + second: int | None = ..., + microsecond: int | None = ..., + nanosecond: int | None = ..., tzinfo: _tzinfo | None = ..., fold: int = ..., ) -> _DatetimeT: ... - def astimezone(self: _DatetimeT, tz: _tzinfo | None = ...) -> _DatetimeT: ... + def astimezone(self: _DatetimeT, tz: _tzinfo | None) -> _DatetimeT: ... def ctime(self) -> str: ... def isoformat(self, sep: str = ..., timespec: str = ...) -> str: ... @classmethod @@ -206,8 +203,6 @@ class Timestamp(datetime): @property def dayofweek(self) -> int: ... @property - def day_of_month(self) -> int: ... - @property def day_of_year(self) -> int: ... @property def dayofyear(self) -> int: ... @@ -224,4 +219,3 @@ class Timestamp(datetime): def days_in_month(self) -> int: ... @property def daysinmonth(self) -> int: ... - def _as_unit(self, unit: str, round_ok: bool = ...) -> Timestamp: ... From 204582efd4133ff565e0bfcbf305776069871aed Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Sat, 16 Jul 2022 14:34:15 -0700 Subject: [PATCH 2/5] make things type check --- pandas/_libs/tslibs/timestamps.pyi | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/tslibs/timestamps.pyi b/pandas/_libs/tslibs/timestamps.pyi index ea4c8ed5c6836..974245c8e9169 100644 --- a/pandas/_libs/tslibs/timestamps.pyi +++ b/pandas/_libs/tslibs/timestamps.pyi @@ -59,6 +59,10 @@ class Timestamp(datetime): # While Timestamp can return pd.NaT, having the constructor return # a Union with NaTType makes things awkward for users of pandas def _set_freq(self, freq: BaseOffset | None) -> None: ... + @classmethod + def _from_value_and_reso( + cls, value: int, reso: int, tz: _tzinfo | None + ) -> Timestamp: ... @property def year(self) -> int: ... @property @@ -114,7 +118,9 @@ class Timestamp(datetime): def date(self) -> _date: ... def time(self) -> _time: ... def timetz(self) -> _time: ... - def replace( + # LSP violation: nanosecond is not present in datetime.datetime.replace + # and has positional args following it + def replace( # type: ignore[override] self: _DatetimeT, year: int | None = ..., month: int | None = ..., @@ -127,7 +133,8 @@ class Timestamp(datetime): tzinfo: _tzinfo | None = ..., fold: int = ..., ) -> _DatetimeT: ... - def astimezone(self: _DatetimeT, tz: _tzinfo | None) -> _DatetimeT: ... + # LSP violation: datetime.datetime.astimezone has a default value for tz + def astimezone(self: _DatetimeT, tz: _tzinfo | None) -> _DatetimeT: ... # type: ignore[override] def ctime(self) -> str: ... def isoformat(self, sep: str = ..., timespec: str = ...) -> str: ... @classmethod From 88b8257b14a404239dfd11558d939d82d3329708 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Sat, 16 Jul 2022 14:35:13 -0700 Subject: [PATCH 3/5] add back _as_unit --- pandas/_libs/tslibs/timestamps.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/_libs/tslibs/timestamps.pyi b/pandas/_libs/tslibs/timestamps.pyi index 974245c8e9169..47607362ad666 100644 --- a/pandas/_libs/tslibs/timestamps.pyi +++ b/pandas/_libs/tslibs/timestamps.pyi @@ -226,3 +226,4 @@ class Timestamp(datetime): def days_in_month(self) -> int: ... @property def daysinmonth(self) -> int: ... + def _as_unit(self, unit: str, round_ok: bool = ...) -> Timestamp: ... From 271c1c66d89ab9a50fd499ad3650305b982b74a3 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Sat, 16 Jul 2022 14:42:58 -0700 Subject: [PATCH 4/5] fix flake8 --- pandas/_libs/tslibs/timestamps.pyi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/timestamps.pyi b/pandas/_libs/tslibs/timestamps.pyi index 47607362ad666..4d242377359ed 100644 --- a/pandas/_libs/tslibs/timestamps.pyi +++ b/pandas/_libs/tslibs/timestamps.pyi @@ -134,7 +134,9 @@ class Timestamp(datetime): fold: int = ..., ) -> _DatetimeT: ... # LSP violation: datetime.datetime.astimezone has a default value for tz - def astimezone(self: _DatetimeT, tz: _tzinfo | None) -> _DatetimeT: ... # type: ignore[override] + def astimezone( # type: ignore[override] + self: _DatetimeT, tz: _tzinfo | None + ) -> _DatetimeT: ... def ctime(self) -> str: ... def isoformat(self, sep: str = ..., timespec: str = ...) -> str: ... @classmethod From e826997cc9d9a92066ab341a1848dc7ddae150aa Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Sat, 16 Jul 2022 15:10:15 -0700 Subject: [PATCH 5/5] more improvements --- pandas/_libs/tslibs/timestamps.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/tslibs/timestamps.pyi b/pandas/_libs/tslibs/timestamps.pyi index 4d242377359ed..082f26cf6f213 100644 --- a/pandas/_libs/tslibs/timestamps.pyi +++ b/pandas/_libs/tslibs/timestamps.pyi @@ -130,8 +130,8 @@ class Timestamp(datetime): second: int | None = ..., microsecond: int | None = ..., nanosecond: int | None = ..., - tzinfo: _tzinfo | None = ..., - fold: int = ..., + tzinfo: _tzinfo | type[object] | None = ..., + fold: int | None = ..., ) -> _DatetimeT: ... # LSP violation: datetime.datetime.astimezone has a default value for tz def astimezone( # type: ignore[override]