From 8b0d76d167b526b9fb2287b2469cdf4e0db9ade9 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Sat, 28 Jan 2023 23:03:54 +0530 Subject: [PATCH 1/6] Modified S1 --- pandas-stubs/_libs/interval.pyi | 12 +++++++++--- pandas-stubs/_libs/tslibs/period.pyi | 12 ++++++------ pandas-stubs/_libs/tslibs/timedeltas.pyi | 17 ++++++----------- pandas-stubs/_libs/tslibs/timestamps.pyi | 8 ++++---- pandas-stubs/core/indexes/interval.pyi | 2 -- 5 files changed, 25 insertions(+), 26 deletions(-) diff --git a/pandas-stubs/_libs/interval.pyi b/pandas-stubs/_libs/interval.pyi index 47ec373c6..3507d3b13 100644 --- a/pandas-stubs/_libs/interval.pyi +++ b/pandas-stubs/_libs/interval.pyi @@ -13,6 +13,10 @@ from pandas import ( Timedelta, Timestamp, ) +from pandas.core.series import ( + TimedeltaSeries, + TimestampSeries, +) from pandas._typing import ( IntervalClosedType, @@ -170,7 +174,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]): @overload def __gt__( self, - other: Series[int] | Series[float] | Series[Timestamp] | Series[Timedelta], + other: Series[int] | Series[float] | TimestampSeries | TimedeltaSeries, ) -> Series[bool]: ... @overload def __lt__(self, other: Interval[_OrderableT]) -> bool: ... @@ -178,7 +182,8 @@ class Interval(IntervalMixin, Generic[_OrderableT]): def __lt__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ... @overload def __lt__( - self, other: Series[int] | Series[float] | Series[Timestamp] | Series[Timedelta] + self, + other: Series[int] | Series[float] | TimestampSeries | TimedeltaSeries, ) -> Series[bool]: ... @overload def __ge__(self, other: Interval[_OrderableT]) -> bool: ... @@ -186,7 +191,8 @@ class Interval(IntervalMixin, Generic[_OrderableT]): def __ge__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ... @overload def __ge__( - self, other: Series[int] | Series[float] | Series[Timestamp] | Series[Timedelta] + self, + other: Series[int] | Series[float] | TimestampSeries | TimedeltaSeries, ) -> Series[bool]: ... @overload def __le__(self, other: Interval[_OrderableT]) -> bool: ... diff --git a/pandas-stubs/_libs/tslibs/period.pyi b/pandas-stubs/_libs/tslibs/period.pyi index bd4cd53f6..b6723d851 100644 --- a/pandas-stubs/_libs/tslibs/period.pyi +++ b/pandas-stubs/_libs/tslibs/period.pyi @@ -101,7 +101,7 @@ class Period(PeriodMixin): @overload def __eq__(self, other: PeriodIndex) -> npt.NDArray[np.bool_]: ... # type: ignore[misc] @overload - def __eq__(self, other: PeriodSeries | Series[Period]) -> Series[bool]: ... # type: ignore[misc] + def __eq__(self, other: PeriodSeries) -> Series[bool]: ... # type: ignore[misc] @overload def __eq__(self, other: object) -> Literal[False]: ... @overload @@ -109,25 +109,25 @@ class Period(PeriodMixin): @overload def __ge__(self, other: PeriodIndex) -> npt.NDArray[np.bool_]: ... @overload - def __ge__(self, other: PeriodSeries | Series[Period]) -> Series[bool]: ... + def __ge__(self, other: PeriodSeries) -> Series[bool]: ... @overload def __gt__(self, other: Period) -> bool: ... @overload def __gt__(self, other: PeriodIndex) -> npt.NDArray[np.bool_]: ... @overload - def __gt__(self, other: PeriodSeries | Series[Period]) -> Series[bool]: ... + def __gt__(self, other: PeriodSeries) -> Series[bool]: ... @overload def __le__(self, other: Period) -> bool: ... @overload def __le__(self, other: PeriodIndex) -> npt.NDArray[np.bool_]: ... @overload - def __le__(self, other: PeriodSeries | Series[Period]) -> Series[bool]: ... + def __le__(self, other: PeriodSeries) -> Series[bool]: ... @overload def __lt__(self, other: Period) -> bool: ... @overload def __lt__(self, other: PeriodIndex) -> npt.NDArray[np.bool_]: ... @overload - def __lt__(self, other: PeriodSeries | Series[Period]) -> Series[bool]: ... + def __lt__(self, other: PeriodSeries) -> Series[bool]: ... # ignore[misc] here because we know all other comparisons # are False, so we use Literal[False] @overload @@ -135,7 +135,7 @@ class Period(PeriodMixin): @overload def __ne__(self, other: PeriodIndex) -> npt.NDArray[np.bool_]: ... # type: ignore[misc] @overload - def __ne__(self, other: PeriodSeries | Series[Period]) -> Series[bool]: ... # type: ignore[misc] + def __ne__(self, other: PeriodSeries) -> Series[bool]: ... # type: ignore[misc] @overload def __ne__(self, other: object) -> Literal[True]: ... # Ignored due to indecipherable error from mypy: diff --git a/pandas-stubs/_libs/tslibs/timedeltas.pyi b/pandas-stubs/_libs/tslibs/timedeltas.pyi index 79211051b..e8debd47f 100644 --- a/pandas-stubs/_libs/tslibs/timedeltas.pyi +++ b/pandas-stubs/_libs/tslibs/timedeltas.pyi @@ -169,12 +169,11 @@ class Timedelta(timedelta): def __add__(self, other: pd.TimedeltaIndex) -> pd.TimedeltaIndex: ... @overload def __add__( - self, other: TimedeltaSeries | Series[pd.Timedelta] + self, + other: TimedeltaSeries | Series[pd.Timedelta], ) -> TimedeltaSeries: ... @overload - def __add__( - self, other: Series[Timestamp] | TimestampSeries - ) -> TimestampSeries: ... + def __add__(self, other: TimestampSeries) -> TimestampSeries: ... @overload def __radd__(self, other: np.datetime64) -> Timestamp: ... @overload @@ -277,9 +276,7 @@ class Timedelta(timedelta): @overload def __floordiv__(self, other: Series[float]) -> TimedeltaSeries: ... @overload - def __floordiv__( - self, other: Series[Timedelta] | TimedeltaSeries - ) -> Series[int]: ... + def __floordiv__(self, other: TimedeltaSeries) -> Series[int]: ... @overload def __floordiv__(self, other: NaTType | None) -> float: ... @overload @@ -300,9 +297,7 @@ class Timedelta(timedelta): self, other: npt.NDArray[np.integer] | npt.NDArray[np.floating] ) -> npt.NDArray[np.timedelta64]: ... @overload - def __truediv__( - self, other: Series[Timedelta] | TimedeltaSeries - ) -> Series[float]: ... + def __truediv__(self, other: TimedeltaSeries) -> Series[float]: ... @overload def __truediv__(self, other: Series[int]) -> TimedeltaSeries: ... @overload @@ -347,7 +342,7 @@ class Timedelta(timedelta): ) -> npt.NDArray[np.timedelta64]: ... @overload def __mod__( - self, other: Series[int] | Series[float] | Series[Timedelta] | TimedeltaSeries + self, other: Series[int] | Series[float] | TimedeltaSeries ) -> TimedeltaSeries: ... def __divmod__(self, other: timedelta) -> tuple[int, Timedelta]: ... # Mypy complains Forward operator "" is not callable, so ignore misc diff --git a/pandas-stubs/_libs/tslibs/timestamps.pyi b/pandas-stubs/_libs/tslibs/timestamps.pyi index 3f5d32adf..407652329 100644 --- a/pandas-stubs/_libs/tslibs/timestamps.pyi +++ b/pandas-stubs/_libs/tslibs/timestamps.pyi @@ -159,25 +159,25 @@ class Timestamp(datetime): @overload def __le__(self, other: Index | npt.NDArray[np.datetime64]) -> np_ndarray_bool: ... @overload - def __le__(self, other: TimestampSeries | Series[Timestamp]) -> Series[bool]: ... + def __le__(self, other: TimestampSeries) -> Series[bool]: ... @overload # type: ignore[override] 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[Timestamp]) -> Series[bool]: ... + def __lt__(self, other: TimestampSeries) -> Series[bool]: ... @overload # type: ignore[override] 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[Timestamp]) -> Series[bool]: ... + def __ge__(self, other: TimestampSeries) -> Series[bool]: ... @overload # type: ignore[override] 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 - def __gt__(self, other: TimestampSeries | Series[Timestamp]) -> Series[bool]: ... + def __gt__(self, other: TimestampSeries) -> Series[bool]: ... # error: Signature of "__add__" incompatible with supertype "date"/"datetime" @overload # type: ignore[override] def __add__( diff --git a/pandas-stubs/core/indexes/interval.pyi b/pandas-stubs/core/indexes/interval.pyi index a3d3aa143..19ee6efe8 100644 --- a/pandas-stubs/core/indexes/interval.pyi +++ b/pandas-stubs/core/indexes/interval.pyi @@ -56,14 +56,12 @@ _EdgesFloat: TypeAlias = Union[ _EdgesTimestamp: TypeAlias = Union[ Sequence[DatetimeLike], npt.NDArray[np.datetime64], - pd.Series[pd.Timestamp], TimestampSeries, pd.DatetimeIndex, ] _EdgesTimedelta: TypeAlias = Union[ Sequence[pd.Timedelta], npt.NDArray[np.timedelta64], - pd.Series[pd.Timedelta], TimedeltaSeries, pd.TimedeltaIndex, ] From dad2902addc303d7c71b513fb1219519d36a2040 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Sat, 28 Jan 2023 23:26:06 +0530 Subject: [PATCH 2/6] Removed two datetime.* --- pandas-stubs/_typing.pyi | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandas-stubs/_typing.pyi b/pandas-stubs/_typing.pyi index 0bb08be20..ae760f9e7 100644 --- a/pandas-stubs/_typing.pyi +++ b/pandas-stubs/_typing.pyi @@ -197,9 +197,7 @@ S1 = TypeVar( str, bytes, datetime.date, - datetime.datetime, datetime.time, - datetime.timedelta, bool, int, float, From 5cadf315e665b503b5fb2de75a2ebc0a7754cacb Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Sun, 29 Jan 2023 04:25:04 +0530 Subject: [PATCH 3/6] req. changes --- pandas-stubs/_libs/tslibs/timedeltas.pyi | 2 +- pandas-stubs/_libs/tslibs/timestamps.pyi | 6 +++--- tests/test_scalars.py | 4 +--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/pandas-stubs/_libs/tslibs/timedeltas.pyi b/pandas-stubs/_libs/tslibs/timedeltas.pyi index e8debd47f..f70709292 100644 --- a/pandas-stubs/_libs/tslibs/timedeltas.pyi +++ b/pandas-stubs/_libs/tslibs/timedeltas.pyi @@ -170,7 +170,7 @@ class Timedelta(timedelta): @overload def __add__( self, - other: TimedeltaSeries | Series[pd.Timedelta], + other: TimedeltaSeries, ) -> TimedeltaSeries: ... @overload def __add__(self, other: TimestampSeries) -> TimestampSeries: ... diff --git a/pandas-stubs/_libs/tslibs/timestamps.pyi b/pandas-stubs/_libs/tslibs/timestamps.pyi index 407652329..06a70d903 100644 --- a/pandas-stubs/_libs/tslibs/timestamps.pyi +++ b/pandas-stubs/_libs/tslibs/timestamps.pyi @@ -189,7 +189,7 @@ class Timestamp(datetime): ) -> _DatetimeT: ... @overload def __add__( - self, other: TimedeltaSeries | Series[Timedelta] + self, other: TimedeltaSeries ) -> TimestampSeries: ... @overload def __add__(self, other: TimedeltaIndex) -> DatetimeIndex: ... @@ -219,7 +219,7 @@ class Timestamp(datetime): @overload def __eq__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc] # pyright: ignore[reportOverlappingOverload] @overload - def __eq__(self, other: TimestampSeries | Series[Timestamp]) -> Series[bool]: ... # type: ignore[misc] + def __eq__(self, other: TimestampSeries | Series[np.datetime64]) -> Series[bool]: ... # type: ignore[misc] @overload def __eq__(self, other: npt.NDArray[np.datetime64] | Index) -> np_ndarray_bool: ... # type: ignore[misc] @overload @@ -227,7 +227,7 @@ class Timestamp(datetime): @overload def __ne__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc] # pyright: ignore[reportOverlappingOverload] @overload - def __ne__(self, other: TimestampSeries | Series[Timestamp]) -> Series[bool]: ... # type: ignore[misc] + def __ne__(self, other: TimestampSeries | Series[np.datetime64]) -> Series[bool]: ... # type: ignore[misc] @overload def __ne__(self, other: npt.NDArray[np.datetime64] | Index) -> np_ndarray_bool: ... # type: ignore[misc] @overload diff --git a/tests/test_scalars.py b/tests/test_scalars.py index 87143e2a6..7814e245d 100644 --- a/tests/test_scalars.py +++ b/tests/test_scalars.py @@ -1256,9 +1256,7 @@ def test_timestamp_cmp() -> None: c_dt_datetime = dt.datetime(year=2000, month=1, day=1) c_datetimeindex = pd.DatetimeIndex(["2000-1-1"]) c_np_ndarray_dt64 = np_dt64_arr - # Typing provided since there is no way to get a Series[Timestamp], - # which is a different type from a TimestampSeries - c_series_dt64: pd.Series[pd.Timestamp] = pd.Series( + c_series_dt64: pd.Series[np.datetime64] = pd.Series( [1, 2, 3], dtype="datetime64[ns]" ) c_series_timestamp = pd.Series(pd.DatetimeIndex(["2000-1-1"])) From 629e7e62d331eecef86e52f0437c71d5c1cc86a5 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Sun, 29 Jan 2023 04:28:19 +0530 Subject: [PATCH 4/6] typo changes --- pandas-stubs/_libs/tslibs/timestamps.pyi | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas-stubs/_libs/tslibs/timestamps.pyi b/pandas-stubs/_libs/tslibs/timestamps.pyi index 06a70d903..d00b7dabc 100644 --- a/pandas-stubs/_libs/tslibs/timestamps.pyi +++ b/pandas-stubs/_libs/tslibs/timestamps.pyi @@ -188,9 +188,7 @@ class Timestamp(datetime): self: _DatetimeT, other: timedelta | np.timedelta64 | Tick ) -> _DatetimeT: ... @overload - def __add__( - self, other: TimedeltaSeries - ) -> TimestampSeries: ... + def __add__(self, other: TimedeltaSeries) -> TimestampSeries: ... @overload def __add__(self, other: TimedeltaIndex) -> DatetimeIndex: ... @overload From ebf02df5d00be04db774ca1e89df2c49c1fa51c6 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Sun, 29 Jan 2023 13:51:24 +0530 Subject: [PATCH 5/6] removed datetime.* and modified the test likewise --- pandas-stubs/_typing.pyi | 2 -- pandas-stubs/core/indexes/accessors.pyi | 13 ++++++------- tests/test_timefuncs.py | 6 +++--- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/pandas-stubs/_typing.pyi b/pandas-stubs/_typing.pyi index ae760f9e7..779f25caf 100644 --- a/pandas-stubs/_typing.pyi +++ b/pandas-stubs/_typing.pyi @@ -196,8 +196,6 @@ S1 = TypeVar( "S1", str, bytes, - datetime.date, - datetime.time, bool, int, float, diff --git a/pandas-stubs/core/indexes/accessors.pyi b/pandas-stubs/core/indexes/accessors.pyi index 5097b2061..86b28cd20 100644 --- a/pandas-stubs/core/indexes/accessors.pyi +++ b/pandas-stubs/core/indexes/accessors.pyi @@ -1,4 +1,3 @@ -import datetime as dt from datetime import tzinfo from typing import ( Generic, @@ -126,10 +125,10 @@ class _DatetimeObjectOps( ): ... _DTOtherOpsDateReturnType = TypeVar( - "_DTOtherOpsDateReturnType", Series[dt.date], np.ndarray + "_DTOtherOpsDateReturnType", Series[np.datetime64], np.ndarray ) _DTOtherOpsTimeReturnType = TypeVar( - "_DTOtherOpsTimeReturnType", Series[dt.time], np.ndarray + "_DTOtherOpsTimeReturnType", Series[np.datetime64], np.ndarray ) class _DatetimeOtherOps(Generic[_DTOtherOpsDateReturnType, _DTOtherOpsTimeReturnType]): @@ -353,8 +352,8 @@ class CombinedDatetimelikeProperties( Series[int], Series[bool], Series, - Series[dt.date], - Series[dt.time], + Series[np.datetime64], + Series[np.datetime64], str, TimestampSeries, Series[str], @@ -370,8 +369,8 @@ class TimestampProperties( Series[int], Series[bool], TimestampSeries, - Series[dt.date], - Series[dt.time], + Series[np.datetime64], + Series[np.datetime64], str, TimestampSeries, Series[str], diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index 8eb392333..0573d914d 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -328,9 +328,9 @@ def test_series_dt_accessors() -> None: s0 = pd.Series(i0) - check(assert_type(s0.dt.date, "pd.Series[dt.date]"), pd.Series, dt.date) - check(assert_type(s0.dt.time, "pd.Series[dt.time]"), pd.Series, dt.time) - check(assert_type(s0.dt.timetz, "pd.Series[dt.time]"), pd.Series, dt.time) + check(assert_type(s0.dt.date, "pd.Series[np.datetime64]"), pd.Series) + check(assert_type(s0.dt.time, "pd.Series[np.datetime64]"), pd.Series) + check(assert_type(s0.dt.timetz, "pd.Series[np.datetime64]"), pd.Series) check(assert_type(s0.dt.year, "pd.Series[int]"), pd.Series, int) check(assert_type(s0.dt.month, "pd.Series[int]"), pd.Series, int) check(assert_type(s0.dt.day, "pd.Series[int]"), pd.Series, int) From 40f8375d2dd42fc190a7ceb2096371df0aa58e60 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Sun, 29 Jan 2023 23:13:25 +0530 Subject: [PATCH 6/6] Reverting changes made in last commit --- pandas-stubs/_typing.pyi | 2 ++ pandas-stubs/core/indexes/accessors.pyi | 13 +++++++------ tests/test_timefuncs.py | 6 +++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/pandas-stubs/_typing.pyi b/pandas-stubs/_typing.pyi index 779f25caf..ae760f9e7 100644 --- a/pandas-stubs/_typing.pyi +++ b/pandas-stubs/_typing.pyi @@ -196,6 +196,8 @@ S1 = TypeVar( "S1", str, bytes, + datetime.date, + datetime.time, bool, int, float, diff --git a/pandas-stubs/core/indexes/accessors.pyi b/pandas-stubs/core/indexes/accessors.pyi index 86b28cd20..5097b2061 100644 --- a/pandas-stubs/core/indexes/accessors.pyi +++ b/pandas-stubs/core/indexes/accessors.pyi @@ -1,3 +1,4 @@ +import datetime as dt from datetime import tzinfo from typing import ( Generic, @@ -125,10 +126,10 @@ class _DatetimeObjectOps( ): ... _DTOtherOpsDateReturnType = TypeVar( - "_DTOtherOpsDateReturnType", Series[np.datetime64], np.ndarray + "_DTOtherOpsDateReturnType", Series[dt.date], np.ndarray ) _DTOtherOpsTimeReturnType = TypeVar( - "_DTOtherOpsTimeReturnType", Series[np.datetime64], np.ndarray + "_DTOtherOpsTimeReturnType", Series[dt.time], np.ndarray ) class _DatetimeOtherOps(Generic[_DTOtherOpsDateReturnType, _DTOtherOpsTimeReturnType]): @@ -352,8 +353,8 @@ class CombinedDatetimelikeProperties( Series[int], Series[bool], Series, - Series[np.datetime64], - Series[np.datetime64], + Series[dt.date], + Series[dt.time], str, TimestampSeries, Series[str], @@ -369,8 +370,8 @@ class TimestampProperties( Series[int], Series[bool], TimestampSeries, - Series[np.datetime64], - Series[np.datetime64], + Series[dt.date], + Series[dt.time], str, TimestampSeries, Series[str], diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index 0573d914d..8eb392333 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -328,9 +328,9 @@ def test_series_dt_accessors() -> None: s0 = pd.Series(i0) - check(assert_type(s0.dt.date, "pd.Series[np.datetime64]"), pd.Series) - check(assert_type(s0.dt.time, "pd.Series[np.datetime64]"), pd.Series) - check(assert_type(s0.dt.timetz, "pd.Series[np.datetime64]"), pd.Series) + check(assert_type(s0.dt.date, "pd.Series[dt.date]"), pd.Series, dt.date) + check(assert_type(s0.dt.time, "pd.Series[dt.time]"), pd.Series, dt.time) + check(assert_type(s0.dt.timetz, "pd.Series[dt.time]"), pd.Series, dt.time) check(assert_type(s0.dt.year, "pd.Series[int]"), pd.Series, int) check(assert_type(s0.dt.month, "pd.Series[int]"), pd.Series, int) check(assert_type(s0.dt.day, "pd.Series[int]"), pd.Series, int)