Skip to content

Commit

Permalink
keep redundancy
Browse files Browse the repository at this point in the history
  • Loading branch information
twoertwein committed Dec 26, 2023
1 parent 5e4f959 commit 2a047e3
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 46 deletions.
3 changes: 2 additions & 1 deletion pandas-stubs/_libs/tslibs/period.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ from pandas import (
Index,
PeriodIndex,
Series,
Timedelta,
TimedeltaIndex,
)
from pandas.core.series import (
Expand All @@ -26,7 +27,7 @@ from pandas._typing import npt
class IncompatibleFrequency(ValueError): ...

_PeriodAddSub: TypeAlias = (
datetime.timedelta | np.timedelta64 | np.int64 | int | BaseOffset
Timedelta | datetime.timedelta | np.timedelta64 | np.int64 | int | BaseOffset
)

_PeriodFreqHow: TypeAlias = Literal[
Expand Down
33 changes: 16 additions & 17 deletions pandas-stubs/_libs/tslibs/timedeltas.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class Timedelta(timedelta):
value: int
def __new__(
cls,
value: str | int | timedelta | np.timedelta64 = ...,
value: str | int | Timedelta | timedelta | np.timedelta64 = ...,
unit: TimeDeltaUnitChoices = ...,
*,
days: float | np.integer | np.floating = ...,
Expand Down Expand Up @@ -144,9 +144,9 @@ class Timedelta(timedelta):
def resolution_string(self) -> str: ...
# Override due to more types supported than dt.timedelta
@overload # type: ignore[override]
def __add__(self, other: timedelta | np.timedelta64) -> Timedelta: ...
def __add__(self, other: timedelta | Timedelta | np.timedelta64) -> Timedelta: ...
@overload
def __add__(self, other: dt.datetime | np.datetime64) -> Timestamp: ...
def __add__(self, other: dt.datetime | np.datetime64 | Timestamp) -> Timestamp: ...
@overload
def __add__(self, other: NaTType) -> NaTType: ...
@overload
Expand Down Expand Up @@ -177,7 +177,7 @@ class Timedelta(timedelta):
@overload
def __radd__(self, other: np.datetime64) -> Timestamp: ...
@overload
def __radd__(self, other: timedelta | np.timedelta64) -> Timedelta: ...
def __radd__(self, other: timedelta | Timedelta | np.timedelta64) -> Timedelta: ...
@overload
def __radd__(self, other: NaTType) -> NaTType: ...
@overload
Expand All @@ -194,7 +194,7 @@ class Timedelta(timedelta):
def __radd__(self, other: pd.PeriodIndex) -> pd.PeriodIndex: ...
# Override due to more types supported than dt.timedelta
@overload # type: ignore[override]
def __sub__(self, other: timedelta | np.timedelta64) -> Timedelta: ...
def __sub__(self, other: timedelta | Timedelta | np.timedelta64) -> Timedelta: ...
@overload
def __sub__(self, other: NaTType) -> NaTType: ...
@overload
Expand All @@ -208,8 +208,7 @@ class Timedelta(timedelta):
self, other: TimedeltaSeries | Series[pd.Timedelta]
) -> TimedeltaSeries: ...
@overload
def __rsub__(self, other: timedelta | np.timedelta64) -> Timedelta: ...
# Timedelta - Timestamp is not allowed but the reverse is
def __rsub__(self, other: timedelta | Timedelta | np.timedelta64) -> Timedelta: ...
@overload
def __rsub__(self, other: dt.datetime | np.datetime64) -> Timestamp: ... # type: ignore[misc]
@overload
Expand Down Expand Up @@ -260,7 +259,7 @@ class Timedelta(timedelta):
# Override due to more types supported than dt.timedelta
# error: Signature of "__floordiv__" incompatible with supertype "timedelta"
@overload # type: ignore[override]
def __floordiv__(self, other: timedelta | np.timedelta64) -> int: ...
def __floordiv__(self, other: timedelta | Timedelta | np.timedelta64) -> int: ...
@overload
def __floordiv__(self, other: float) -> Timedelta: ...
@overload
Expand All @@ -282,7 +281,7 @@ class Timedelta(timedelta):
@overload
def __floordiv__(self, other: NaTType | None) -> float: ...
@overload
def __rfloordiv__(self, other: timedelta | str) -> int: ...
def __rfloordiv__(self, other: timedelta | Timedelta | str) -> int: ...
@overload
def __rfloordiv__(self, other: NaTType | None) -> float: ...
@overload
Expand All @@ -291,7 +290,7 @@ class Timedelta(timedelta):
) -> npt.NDArray[np.int_]: ...
# Override due to more types supported than dt.timedelta
@overload # type: ignore[override]
def __truediv__(self, other: timedelta | NaTType) -> float: ...
def __truediv__(self, other: timedelta | Timedelta | NaTType) -> float: ...
@overload
def __truediv__(self, other: float) -> Timedelta: ...
@overload
Expand All @@ -306,10 +305,10 @@ class Timedelta(timedelta):
def __truediv__(self, other: Series[float]) -> TimedeltaSeries: ...
@overload
def __truediv__(self, other: Index[int] | Index[float]) -> TimedeltaIndex: ...
def __rtruediv__(self, other: timedelta | NaTType) -> float: ...
def __rtruediv__(self, other: timedelta | Timedelta | NaTType) -> float: ...
# Override due to more types supported than dt.timedelta
@overload
def __eq__(self, other: timedelta | np.timedelta64) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
def __eq__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __eq__(self, other: TimedeltaSeries | Series[pd.Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
@overload
Expand All @@ -320,7 +319,7 @@ class Timedelta(timedelta):
def __eq__(self, other: object) -> Literal[False]: ...
# Override due to more types supported than dt.timedelta
@overload
def __ne__(self, other: timedelta | np.timedelta64) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
def __ne__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __ne__(self, other: TimedeltaSeries | Series[pd.Timedelta]) -> Series[bool]: ... # type: ignore[overload-overlap]
@overload
Expand Down Expand Up @@ -351,7 +350,7 @@ class Timedelta(timedelta):
# for le, lt ge and gt
# Override due to more types supported than dt.timedelta
@overload # type: ignore[override]
def __le__(self, other: timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
def __le__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
@overload
def __le__(
self, other: TimedeltaIndex | npt.NDArray[np.timedelta64]
Expand All @@ -360,7 +359,7 @@ class Timedelta(timedelta):
def __le__(self, other: TimedeltaSeries | Series[pd.Timedelta]) -> Series[bool]: ...
# Override due to more types supported than dt.timedelta
@overload # type: ignore[override]
def __lt__(self, other: timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
def __lt__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
@overload
def __lt__(
self, other: TimedeltaIndex | npt.NDArray[np.timedelta64]
Expand All @@ -369,7 +368,7 @@ class Timedelta(timedelta):
def __lt__(self, other: TimedeltaSeries | Series[pd.Timedelta]) -> Series[bool]: ...
# Override due to more types supported than dt.timedelta
@overload # type: ignore[override]
def __ge__(self, other: timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
def __ge__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
@overload
def __ge__(
self, other: TimedeltaIndex | npt.NDArray[np.timedelta64]
Expand All @@ -378,7 +377,7 @@ class Timedelta(timedelta):
def __ge__(self, other: TimedeltaSeries | Series[pd.Timedelta]) -> Series[bool]: ...
# Override due to more types supported than dt.timedelta
@overload # type: ignore[override]
def __gt__(self, other: timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
def __gt__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
@overload
def __gt__(
self, other: TimedeltaIndex | npt.NDArray[np.timedelta64]
Expand Down
29 changes: 10 additions & 19 deletions pandas-stubs/_libs/tslibs/timestamps.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ from datetime import (
timedelta,
tzinfo as _tzinfo,
)
import sys
from time import struct_time
from typing import (
ClassVar,
Expand Down Expand Up @@ -44,7 +43,7 @@ from pandas._typing import (

_Ambiguous: TypeAlias = bool | Literal["raise", "NaT"]
_Nonexistent: TypeAlias = (
Literal["raise", "NaT", "shift_backward", "shift_forward"] | timedelta
Literal["raise", "NaT", "shift_backward", "shift_forward"] | Timedelta | timedelta
)

class Timestamp(datetime):
Expand Down Expand Up @@ -100,16 +99,8 @@ class Timestamp(datetime):
def tz(self) -> _tzinfo | None: ...
@property
def fold(self) -> int: ...

if sys.version_info < (3, 12):
@classmethod
def fromtimestamp(cls, t: float, tz: _tzinfo | str | None = ...) -> Self: ...
else:
@classmethod
def fromtimestamp( # pyright: ignore[reportIncompatibleMethodOverride]
cls, t: float, tz: _tzinfo | str | None = ...
) -> Self: ...

@classmethod
def fromtimestamp(cls, t: float, tz: _tzinfo | str | None = ...) -> Self: ...
@classmethod
def utcfromtimestamp(cls, ts: float) -> Self: ...
@classmethod
Expand Down Expand Up @@ -166,25 +157,25 @@ class Timestamp(datetime):
# Mypy complains Forward operator "<inequality op>" is not callable, so ignore misc
# for le, lt ge and gt
@overload # type: ignore[override]
def __le__(self, other: datetime | np.datetime64) -> bool: ... # type: ignore[misc]
def __le__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc]
@overload
def __le__(self, other: Index | npt.NDArray[np.datetime64]) -> np_ndarray_bool: ...
@overload
def __le__(self, other: TimestampSeries) -> Series[bool]: ...
@overload # type: ignore[override]
def __lt__(self, other: datetime | np.datetime64) -> bool: ... # type: ignore[misc]
def __lt__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc]
@overload
def __lt__(self, other: Index | npt.NDArray[np.datetime64]) -> np_ndarray_bool: ...
@overload
def __lt__(self, other: TimestampSeries) -> Series[bool]: ...
@overload # type: ignore[override]
def __ge__(self, other: datetime | np.datetime64) -> bool: ... # type: ignore[misc]
def __ge__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc]
@overload
def __ge__(self, other: Index | npt.NDArray[np.datetime64]) -> np_ndarray_bool: ...
@overload
def __ge__(self, other: TimestampSeries) -> Series[bool]: ...
@overload # type: ignore[override]
def __gt__(self, other: datetime | np.datetime64) -> bool: ... # type: ignore[misc]
def __gt__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc]
@overload
def __gt__(self, other: Index | npt.NDArray[np.datetime64]) -> np_ndarray_bool: ...
@overload
Expand All @@ -210,7 +201,7 @@ class Timestamp(datetime):
) -> npt.NDArray[np.datetime64]: ...
# TODO: test dt64
@overload # type: ignore[override]
def __sub__(self, other: datetime | np.datetime64) -> Timedelta: ...
def __sub__(self, other: Timestamp | datetime | np.datetime64) -> Timedelta: ...
@overload
def __sub__(self, other: timedelta | np.timedelta64 | Tick) -> Self: ...
@overload
Expand All @@ -222,15 +213,15 @@ class Timestamp(datetime):
self, other: npt.NDArray[np.timedelta64]
) -> npt.NDArray[np.datetime64]: ...
@overload
def __eq__(self, other: datetime | np.datetime64) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
def __eq__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __eq__(self, other: TimestampSeries) -> Series[bool]: ... # type: ignore[overload-overlap]
@overload
def __eq__(self, other: npt.NDArray[np.datetime64] | Index) -> np_ndarray_bool: ... # type: ignore[overload-overlap]
@overload
def __eq__(self, other: object) -> Literal[False]: ...
@overload
def __ne__(self, other: datetime | np.datetime64) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
def __ne__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
@overload
def __ne__(self, other: TimestampSeries) -> Series[bool]: ... # type: ignore[overload-overlap]
@overload
Expand Down
7 changes: 4 additions & 3 deletions pandas-stubs/core/indexes/datetimes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import numpy as np
from pandas import (
DataFrame,
Index,
Timedelta,
TimedeltaIndex,
Timestamp,
)
Expand Down Expand Up @@ -90,7 +91,7 @@ def date_range(
start: str | DateAndDatetimeLike | None = ...,
end: str | DateAndDatetimeLike | None = ...,
periods: int | None = ...,
freq: str | timedelta | BaseOffset = ...,
freq: str | timedelta | Timedelta | BaseOffset = ...,
tz: str | tzinfo = ...,
normalize: bool = ...,
name: Hashable | None = ...,
Expand All @@ -102,7 +103,7 @@ def bdate_range(
start: str | DateAndDatetimeLike | None = ...,
end: str | DateAndDatetimeLike | None = ...,
periods: int | None = ...,
freq: str | timedelta | BaseOffset = ...,
freq: str | timedelta | Timedelta | BaseOffset = ...,
tz: str | tzinfo = ...,
normalize: bool = ...,
name: Hashable | None = ...,
Expand All @@ -116,7 +117,7 @@ def bdate_range(
end: str | DateAndDatetimeLike | None = ...,
periods: int | None = ...,
*,
freq: str | timedelta | BaseOffset,
freq: str | timedelta | Timedelta | BaseOffset,
tz: str | tzinfo = ...,
normalize: bool = ...,
name: Hashable | None = ...,
Expand Down
4 changes: 2 additions & 2 deletions pandas-stubs/core/indexes/timedeltas.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class TimedeltaIndex(DatetimeTimedeltaMixin[Timedelta], TimedeltaIndexProperties
cls,
data: AnyArrayLike
| list[str]
| Sequence[dt.timedelta | np.timedelta64 | float] = ...,
| Sequence[dt.timedelta | Timedelta | np.timedelta64 | float] = ...,
unit: Literal["D", "h", "m", "s", "ms", "us", "ns"] = ...,
freq: str | BaseOffset = ...,
closed: object = ...,
Expand Down Expand Up @@ -79,7 +79,7 @@ def timedelta_range(
start: TimedeltaConvertibleTypes = ...,
end: TimedeltaConvertibleTypes = ...,
periods: int | None = ...,
freq: str | DateOffset | dt.timedelta | None = ...,
freq: str | DateOffset | Timedelta | dt.timedelta | None = ...,
name: Hashable | None = ...,
closed: Literal["left", "right"] | None = ...,
) -> TimedeltaIndex: ...
12 changes: 8 additions & 4 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1538,15 +1538,17 @@ class Series(IndexOpsMixin[S1], NDFrame):
@overload
def __sub__(
self: Series[Timestamp],
other: timedelta | TimedeltaSeries | TimedeltaIndex | np.timedelta64,
other: Timedelta | TimedeltaSeries | TimedeltaIndex | np.timedelta64,
) -> TimestampSeries: ...
@overload
def __sub__(
self: Series[Timedelta],
other: timedelta | TimedeltaSeries | TimedeltaIndex | np.timedelta64,
other: Timedelta | TimedeltaSeries | TimedeltaIndex | np.timedelta64,
) -> TimedeltaSeries: ...
@overload
def __sub__(self, other: datetime | TimestampSeries) -> TimedeltaSeries: ...
def __sub__(
self, other: Timestamp | datetime | TimestampSeries
) -> TimedeltaSeries: ...
@overload
def __sub__(self, other: num | _ListLike | Series) -> Series: ...
def __truediv__(self, other: num | _ListLike | Series[S1]) -> Series: ...
Expand Down Expand Up @@ -1999,7 +2001,9 @@ class TimestampSeries(Series[Timestamp]):
def __add__(self, other: TimedeltaSeries | np.timedelta64 | timedelta) -> TimestampSeries: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
def __radd__(self, other: TimedeltaSeries | np.timedelta64 | timedelta) -> TimestampSeries: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
@overload # type: ignore[override]
def __sub__(self, other: datetime | TimestampSeries) -> TimedeltaSeries: ...
def __sub__(
self, other: Timestamp | datetime | TimestampSeries
) -> TimedeltaSeries: ...
@overload
def __sub__( # pyright: ignore[reportIncompatibleMethodOverride]
self,
Expand Down

0 comments on commit 2a047e3

Please sign in to comment.