Skip to content

Commit

Permalink
Typing: More precise NaT stub (#60002)
Browse files Browse the repository at this point in the history
* more precise NaT stub

* ruff format

* updated == and != to return literal
  • Loading branch information
randolf-scholz authored Oct 8, 2024
1 parent 5126dca commit 5ea5bd9
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions pandas/_libs/tslibs/nattype.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@ NaT: NaTType
iNaT: int
nat_strings: set[str]

_NaTComparisonTypes: TypeAlias = (
datetime | timedelta | Period | np.datetime64 | np.timedelta64
)

class _NatComparison:
def __call__(self, other: _NaTComparisonTypes) -> bool: ...
_TimeLike: TypeAlias = datetime | timedelta | Period | np.datetime64 | np.timedelta64
_TimeDelta: TypeAlias = timedelta | np.timedelta64

class NaTType:
_value: np.int64
Expand Down Expand Up @@ -161,30 +157,30 @@ class NaTType:
@property
def qyear(self) -> float: ...
# comparisons
def __eq__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...
__lt__: _NatComparison
__le__: _NatComparison
__gt__: _NatComparison
__ge__: _NatComparison
def __eq__(self, other: object, /) -> Literal[False]: ...
def __ne__(self, other: object, /) -> Literal[True]: ...
def __lt__(self, other: Self | _TimeLike, /) -> Literal[False]: ...
def __le__(self, other: Self | _TimeLike, /) -> Literal[False]: ...
def __gt__(self, other: Self | _TimeLike, /) -> Literal[False]: ...
def __ge__(self, other: Self | _TimeLike, /) -> Literal[False]: ...
# unary operators
def __pos__(self) -> Self: ...
def __neg__(self) -> Self: ...
# binary operators
def __sub__(self, other: Self | timedelta | datetime) -> Self: ...
def __rsub__(self, other: Self | timedelta | datetime) -> Self: ...
def __add__(self, other: Self | timedelta | datetime) -> Self: ...
def __radd__(self, other: Self | timedelta | datetime) -> Self: ...
def __mul__(self, other: float) -> Self: ... # analogous to timedelta
def __rmul__(self, other: float) -> Self: ...
def __sub__(self, other: Self | _TimeLike, /) -> Self: ...
def __rsub__(self, other: Self | _TimeLike, /) -> Self: ...
def __add__(self, other: Self | _TimeLike, /) -> Self: ...
def __radd__(self, other: Self | _TimeLike, /) -> Self: ...
def __mul__(self, other: float, /) -> Self: ... # analogous to timedelta
def __rmul__(self, other: float, /) -> Self: ...
@overload # analogous to timedelta
def __truediv__(self, other: Self | timedelta) -> float: ... # Literal[NaN]
def __truediv__(self, other: Self | _TimeDelta, /) -> float: ... # Literal[NaN]
@overload
def __truediv__(self, other: float) -> Self: ...
def __truediv__(self, other: float, /) -> Self: ...
@overload # analogous to timedelta
def __floordiv__(self, other: Self | timedelta) -> float: ... # Literal[NaN]
def __floordiv__(self, other: Self | _TimeDelta, /) -> float: ... # Literal[NaN]
@overload
def __floordiv__(self, other: float) -> Self: ...
def __floordiv__(self, other: float, /) -> Self: ...
# other
def __hash__(self) -> int: ...
def as_unit(self, unit: str, round_ok: bool = ...) -> NaTType: ...

0 comments on commit 5ea5bd9

Please sign in to comment.