Skip to content

TYP: timestamps.pyi followup #44975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 30 additions & 26 deletions pandas/_libs/tslibs/timestamps.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ from pandas._libs.tslibs import (
Timedelta,
)

_S = TypeVar("_S", bound=datetime)
_DatetimeT = TypeVar("_DatetimeT", bound=datetime)

def integer_op_not_supported(obj: object) -> TypeError: ...

Expand All @@ -34,7 +34,7 @@ class Timestamp(datetime):

# error: "__new__" must return a class instance (got "Union[Timestamp, NaTType]")
def __new__( # type: ignore[misc]
cls: type[_S],
cls: type[_DatetimeT],
ts_input: int
| np.integer
| float
Expand All @@ -56,7 +56,7 @@ class Timestamp(datetime):
tzinfo: _tzinfo | None = ...,
*,
fold: int | None = ...,
) -> _S | NaTType: ...
) -> _DatetimeT | NaTType: ...
def _set_freq(self, freq: BaseOffset | None) -> None: ...
@property
def year(self) -> int: ...
Expand All @@ -79,27 +79,29 @@ class Timestamp(datetime):
@property
def fold(self) -> int: ...
@classmethod
def fromtimestamp(cls: type[_S], t: float, tz: _tzinfo | None = ...) -> _S: ...
def fromtimestamp(
cls: type[_DatetimeT], t: float, tz: _tzinfo | None = ...
) -> _DatetimeT: ...
@classmethod
def utcfromtimestamp(cls: type[_S], t: float) -> _S: ...
def utcfromtimestamp(cls: type[_DatetimeT], t: float) -> _DatetimeT: ...
@classmethod
def today(cls: type[_S], tz: _tzinfo | str | None = ...) -> _S: ...
def today(cls: type[_DatetimeT], tz: _tzinfo | str | None = ...) -> _DatetimeT: ...
@classmethod
def fromordinal(
cls: type[_S],
cls: type[_DatetimeT],
ordinal: int,
freq: str | BaseOffset | None = ...,
tz: _tzinfo | str | None = ...,
) -> _S: ...
) -> _DatetimeT: ...
@classmethod
def now(cls: type[_S], tz: _tzinfo | str | None = ...) -> _S: ...
def now(cls: type[_DatetimeT], tz: _tzinfo | str | None = ...) -> _DatetimeT: ...
@classmethod
def utcnow(cls: type[_S]) -> _S: ...
def utcnow(cls: type[_DatetimeT]) -> _DatetimeT: ...
# error: Signature of "combine" incompatible with supertype "datetime"
@classmethod
def combine(cls, date: _date, time: _time) -> datetime: ... # type: ignore[override]
@classmethod
def fromisoformat(cls: type[_S], date_string: str) -> _S: ...
def fromisoformat(cls: type[_DatetimeT], date_string: str) -> _DatetimeT: ...
def strftime(self, format: str) -> str: ...
def __format__(self, fmt: str) -> str: ...
def toordinal(self) -> int: ...
Expand All @@ -121,10 +123,9 @@ class Timestamp(datetime):
tzinfo: _tzinfo | None = ...,
fold: int = ...,
) -> datetime: ...
def astimezone(self: _S, tz: _tzinfo | None = ...) -> _S: ...
def astimezone(self: _DatetimeT, tz: _tzinfo | None = ...) -> _DatetimeT: ...
def ctime(self) -> str: ...
# error: Signature of "isoformat" incompatible with supertype "datetime"
def isoformat(self, sep: str = ...) -> str: ... # type: ignore[override]
def isoformat(self, sep: str = ..., timespec: str = ...) -> str: ...
@classmethod
def strptime(cls, date_string: str, format: str) -> datetime: ...
def utcoffset(self) -> timedelta | None: ...
Expand All @@ -139,8 +140,8 @@ class Timestamp(datetime):
def __add__(self, other: np.ndarray) -> np.ndarray: ...
@overload
# TODO: other can also be Tick (but it cannot be resolved)
def __add__(self: _S, other: timedelta | np.timedelta64) -> _S: ...
def __radd__(self: _S, other: timedelta) -> _S: ...
def __add__(self: _DatetimeT, other: timedelta | np.timedelta64) -> _DatetimeT: ...
def __radd__(self: _DatetimeT, other: timedelta) -> _DatetimeT: ...
@overload # type: ignore
def __sub__(self, other: datetime) -> timedelta: ...
@overload
Expand Down Expand Up @@ -170,22 +171,25 @@ class Timestamp(datetime):
def to_julian_date(self) -> np.float64: ...
@property
def asm8(self) -> np.datetime64: ...
def tz_convert(self: _S, tz: _tzinfo | str | None) -> _S: ...
def tz_convert(self: _DatetimeT, tz: _tzinfo | str | None) -> _DatetimeT: ...
# TODO: could return NaT?
def tz_localize(
self: _S, tz: _tzinfo | str | None, ambiguous: str = ..., nonexistent: str = ...
) -> _S: ...
def normalize(self: _S) -> _S: ...
self: _DatetimeT,
tz: _tzinfo | str | None,
ambiguous: str = ...,
nonexistent: str = ...,
) -> _DatetimeT: ...
def normalize(self: _DatetimeT) -> _DatetimeT: ...
# TODO: round/floor/ceil could return NaT?
def round(
self: _S, freq: str, ambiguous: bool | str = ..., nonexistent: str = ...
) -> _S: ...
self: _DatetimeT, freq: str, ambiguous: bool | str = ..., nonexistent: str = ...
) -> _DatetimeT: ...
def floor(
self: _S, freq: str, ambiguous: bool | str = ..., nonexistent: str = ...
) -> _S: ...
self: _DatetimeT, freq: str, ambiguous: bool | str = ..., nonexistent: str = ...
) -> _DatetimeT: ...
def ceil(
self: _S, freq: str, ambiguous: bool | str = ..., nonexistent: str = ...
) -> _S: ...
self: _DatetimeT, freq: str, ambiguous: bool | str = ..., nonexistent: str = ...
) -> _DatetimeT: ...
def day_name(self, locale: str | None = ...) -> str: ...
def month_name(self, locale: str | None = ...) -> str: ...
@property
Expand Down