From acd9ac8b0bbb0a32ab7fd796b02e0ad3b90708ee Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Sat, 19 Nov 2022 00:42:35 +0530 Subject: [PATCH 01/21] update --- pandas-stubs/core/series.pyi | 14 +++++++++----- tests/test_timefuncs.py | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index b017b6840..11fd19062 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -1211,7 +1211,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]): def __add__(self, other: Timestamp) -> TimestampSeries: ... @overload def __add__( - self, other: num | _str | Timedelta | _ListLike | Series[S1] + self, other: num | _str | Timedelta | _ListLike | Series[S1] | np.timedelta64 ) -> Series: ... # ignore needed for mypy as we want different results based on the arguments @overload @@ -1243,7 +1243,9 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]): def __le__(self, other: S1 | _ListLike | Series[S1]) -> Series[_bool]: ... def __lt__(self, other: S1 | _ListLike | Series[S1]) -> Series[_bool]: ... @overload - def __mul__(self, other: Timedelta | TimedeltaSeries) -> TimedeltaSeries: ... + def __mul__( + self, other: Timedelta | TimedeltaSeries | np.timedelta64 + ) -> TimedeltaSeries: ... @overload def __mul__(self, other: num | _ListLike | Series) -> Series: ... def __mod__(self, other: num | _ListLike | Series[S1]) -> Series[S1]: ... @@ -1304,17 +1306,19 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]): ) -> TimedeltaSeries: ... @overload def __sub__( - self: Series[Timestamp], other: Timedelta | TimedeltaSeries | TimedeltaIndex + self: Series[Timestamp], + other: Timedelta | TimedeltaSeries | TimedeltaIndex | np.timedelta64, ) -> TimestampSeries: ... @overload def __sub__( - self: Series[Timedelta], other: Timedelta | TimedeltaSeries | TimedeltaIndex + self: Series[Timedelta], + other: Timedelta | TimedeltaSeries | TimedeltaIndex | np.timedelta64, ) -> TimedeltaSeries: ... @overload def __sub__(self, other: num | _ListLike | Series) -> Series: ... @overload def __truediv__( - self, other: Timedelta | TimedeltaSeries | TimedeltaIndex + self, other: Timedelta | TimedeltaSeries | TimedeltaIndex | np.timedelta64 ) -> Series[float]: ... @overload def __truediv__(self, other: num | _ListLike | Series[S1]) -> Series: ... diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index 62eebf6a4..524646ed5 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -1035,3 +1035,28 @@ def test_timedelta_range() -> None: def test_dateoffset_freqstr() -> None: offset = DateOffset(minutes=10) check(assert_type(offset.freqstr, str), str) + + +def timedelta64_and_arithmatic_operator() -> None: + s1 = pd.Series(data=pd.date_range("1/1/2020", "2/1/2020")) + s2 = pd.Series(data=pd.date_range("1/1/2021", "2/1/2021")) + check(assert_type((s1 - np.timedelta64(1, "M")), np.timedelta64), np.timedelta64) + check(assert_type((s1 + np.timedelta64(1, "M")), np.timedelta64), np.timedelta64) + check(assert_type(((s1 * np.timedelta64(1, "M")), np.timedelta64), np.timedelta64)) + check(assert_type(((s1 / np.timedelta64(1, "M")), np.timedelta64), np.timedelta64)) + check( + assert_type(((s1 - s2) - np.timedelta64(1, "M")), np.timedelta64), + np.timedelta64, + ) + check( + assert_type(((s1 + s2) / np.timedelta64(1, "M")), np.timedelta64), + np.timedelta64, + ) + check( + assert_type(((s1 * s2) / np.timedelta64(1, "M")), np.timedelta64), + np.timedelta64, + ) + check( + assert_type(((s1 / s2) / np.timedelta64(1, "M")), np.timedelta64), + np.timedelta64, + ) From 19a7df2eb3b436e9b9cf81d25a2741e7a8ba648c Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Sat, 19 Nov 2022 13:48:02 +0530 Subject: [PATCH 02/21] update --- pandas-stubs/core/series.pyi | 6 +++--- tests/test_timefuncs.py | 28 +++++++++++++++------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index 11fd19062..3ccb26b3c 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -1751,11 +1751,11 @@ class TimedeltaSeries(Series[Timedelta]): @overload def __add__(self, other: Timestamp | DatetimeIndex) -> TimestampSeries: ... @overload - def __add__(self, other: Timedelta) -> TimedeltaSeries: ... + def __add__(self, other: Timedelta | np.timedelta64) -> TimedeltaSeries: ... def __radd__(self, pther: Timestamp | TimestampSeries) -> TimestampSeries: ... # type: ignore[override] - def __mul__(self, other: num) -> TimedeltaSeries: ... # type: ignore[override] + def __mul__(self, other: num | np.timedelta64) -> TimedeltaSeries: ... # type: ignore[override] def __sub__( # type: ignore[override] - self, other: Timedelta | TimedeltaSeries | TimedeltaIndex + self, other: Timedelta | TimedeltaSeries | TimedeltaIndex | np.timedelta64 ) -> TimedeltaSeries: ... @property def dt(self) -> TimedeltaProperties: ... # type: ignore[override] diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index 524646ed5..3b8a097a8 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -1040,23 +1040,25 @@ def test_dateoffset_freqstr() -> None: def timedelta64_and_arithmatic_operator() -> None: s1 = pd.Series(data=pd.date_range("1/1/2020", "2/1/2020")) s2 = pd.Series(data=pd.date_range("1/1/2021", "2/1/2021")) - check(assert_type((s1 - np.timedelta64(1, "M")), np.timedelta64), np.timedelta64) - check(assert_type((s1 + np.timedelta64(1, "M")), np.timedelta64), np.timedelta64) - check(assert_type(((s1 * np.timedelta64(1, "M")), np.timedelta64), np.timedelta64)) - check(assert_type(((s1 / np.timedelta64(1, "M")), np.timedelta64), np.timedelta64)) - check( - assert_type(((s1 - s2) - np.timedelta64(1, "M")), np.timedelta64), - np.timedelta64, + s3 = s2 - s1 + td = np.timedelta64(1, "M") + check(assert_type((s1 - td), pd.Series), pd.Timestamp) + check(assert_type((s1 + td), pd.Series), pd.Timestamp) + check(assert_type((s1 * td), pd.Series), pd.Timestamp) + check(assert_type((s1 / td), pd.Series), pd.Timestamp) + check( + assert_type((s3 - td), pd.Series), + pd.Series, ) check( - assert_type(((s1 + s2) / np.timedelta64(1, "M")), np.timedelta64), - np.timedelta64, + assert_type((s3 + td), pd.Series), + pd.Series, ) check( - assert_type(((s1 * s2) / np.timedelta64(1, "M")), np.timedelta64), - np.timedelta64, + assert_type((s3 * td), pd.Series), + pd.Series, ) check( - assert_type(((s1 / s2) / np.timedelta64(1, "M")), np.timedelta64), - np.timedelta64, + assert_type((s3 / td), pd.Series), + pd.Series, ) From e06f5830ab8d6e58c1e572100b82b96013daef21 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Sat, 19 Nov 2022 14:19:25 +0530 Subject: [PATCH 03/21] Update test_timefuncs.py --- tests/test_timefuncs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index 3b8a097a8..87624d995 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -1042,7 +1042,7 @@ def timedelta64_and_arithmatic_operator() -> None: s2 = pd.Series(data=pd.date_range("1/1/2021", "2/1/2021")) s3 = s2 - s1 td = np.timedelta64(1, "M") - check(assert_type((s1 - td), pd.Series), pd.Timestamp) + check(assert_type((s1 - td), np.timedelta64), pd.Timestamp) check(assert_type((s1 + td), pd.Series), pd.Timestamp) check(assert_type((s1 * td), pd.Series), pd.Timestamp) check(assert_type((s1 / td), pd.Series), pd.Timestamp) From fb9dc01fb5563aee8b7e6a3874e4220bb6b61426 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Sat, 19 Nov 2022 14:52:48 +0530 Subject: [PATCH 04/21] Update test_timefuncs.py --- tests/test_timefuncs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index 87624d995..f0264088e 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -1042,7 +1042,7 @@ def timedelta64_and_arithmatic_operator() -> None: s2 = pd.Series(data=pd.date_range("1/1/2021", "2/1/2021")) s3 = s2 - s1 td = np.timedelta64(1, "M") - check(assert_type((s1 - td), np.timedelta64), pd.Timestamp) + check(assert_type((s1 - td), pd.Timestamp), np.timedelta64) check(assert_type((s1 + td), pd.Series), pd.Timestamp) check(assert_type((s1 * td), pd.Series), pd.Timestamp) check(assert_type((s1 / td), pd.Series), pd.Timestamp) From 83aa4c067ab5ed178f9de59cab31a2ed86c87b2f Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Sat, 19 Nov 2022 14:57:26 +0530 Subject: [PATCH 05/21] Update test_timefuncs.py --- tests/test_timefuncs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index f0264088e..76dd53166 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -1042,7 +1042,7 @@ def timedelta64_and_arithmatic_operator() -> None: s2 = pd.Series(data=pd.date_range("1/1/2021", "2/1/2021")) s3 = s2 - s1 td = np.timedelta64(1, "M") - check(assert_type((s1 - td), pd.Timestamp), np.timedelta64) + check(assert_type((s1 - td), pd.TimestampSeries), np.timedelta64) check(assert_type((s1 + td), pd.Series), pd.Timestamp) check(assert_type((s1 * td), pd.Series), pd.Timestamp) check(assert_type((s1 / td), pd.Series), pd.Timestamp) From 9fc4c76c0dcea81866fbe8062480589924ce3e23 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Sat, 19 Nov 2022 15:02:14 +0530 Subject: [PATCH 06/21] Update test_timefuncs.py --- tests/test_timefuncs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index 76dd53166..3dbfb7c8e 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -1043,7 +1043,7 @@ def timedelta64_and_arithmatic_operator() -> None: s3 = s2 - s1 td = np.timedelta64(1, "M") check(assert_type((s1 - td), pd.TimestampSeries), np.timedelta64) - check(assert_type((s1 + td), pd.Series), pd.Timestamp) + check(assert_type((s1 + td), pd.Series), pd.TimestampSeries) check(assert_type((s1 * td), pd.Series), pd.Timestamp) check(assert_type((s1 / td), pd.Series), pd.Timestamp) check( From dda43a99986fcd4d759955d42cffd8a33badc0b4 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Sat, 19 Nov 2022 15:12:48 +0530 Subject: [PATCH 07/21] Update test_timefuncs.py --- tests/test_timefuncs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index 3dbfb7c8e..4ba5bd1f1 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -1042,7 +1042,7 @@ def timedelta64_and_arithmatic_operator() -> None: s2 = pd.Series(data=pd.date_range("1/1/2021", "2/1/2021")) s3 = s2 - s1 td = np.timedelta64(1, "M") - check(assert_type((s1 - td), pd.TimestampSeries), np.timedelta64) + check(assert_type((s1 - td), TimestampSeries), np.timedelta64) check(assert_type((s1 + td), pd.Series), pd.TimestampSeries) check(assert_type((s1 * td), pd.Series), pd.Timestamp) check(assert_type((s1 / td), pd.Series), pd.Timestamp) From 994c6dbccb06c5ed23cb8b2828fb757408a8187d Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Sat, 19 Nov 2022 15:19:15 +0530 Subject: [PATCH 08/21] Update test_timefuncs.py --- tests/test_timefuncs.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index 4ba5bd1f1..f69b34797 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -1043,22 +1043,22 @@ def timedelta64_and_arithmatic_operator() -> None: s3 = s2 - s1 td = np.timedelta64(1, "M") check(assert_type((s1 - td), TimestampSeries), np.timedelta64) - check(assert_type((s1 + td), pd.Series), pd.TimestampSeries) - check(assert_type((s1 * td), pd.Series), pd.Timestamp) - check(assert_type((s1 / td), pd.Series), pd.Timestamp) + check(assert_type((s1 + td), TimestampSeries), np.timedelta64) + check(assert_type((s1 * td), TimestampSeries), np.timedelta64) + check(assert_type((s1 / td), TimestampSeries), np.timedelta64) check( - assert_type((s3 - td), pd.Series), + assert_type((s3 - td), TimestampSeries), pd.Series, ) check( - assert_type((s3 + td), pd.Series), + assert_type((s3 + td), TimestampSeries), pd.Series, ) check( - assert_type((s3 * td), pd.Series), + assert_type((s3 * td), TimestampSeries), pd.Series, ) check( - assert_type((s3 / td), pd.Series), + assert_type((s3 / td), TimestampSeries), pd.Series, ) From c0ea3b0f2647adb3fff4623832d92212b9b03492 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Sat, 19 Nov 2022 15:24:54 +0530 Subject: [PATCH 09/21] Update test_timefuncs.py --- tests/test_timefuncs.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index f69b34797..c48f98994 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -1043,22 +1043,22 @@ def timedelta64_and_arithmatic_operator() -> None: s3 = s2 - s1 td = np.timedelta64(1, "M") check(assert_type((s1 - td), TimestampSeries), np.timedelta64) - check(assert_type((s1 + td), TimestampSeries), np.timedelta64) - check(assert_type((s1 * td), TimestampSeries), np.timedelta64) - check(assert_type((s1 / td), TimestampSeries), np.timedelta64) + check(assert_type((s1 + td), Series), np.timedelta64) + check(assert_type((s1 * td), TimedeltaSeries), np.timedelta64) + check(assert_type((s1 / td), Series), np.timedelta64) check( - assert_type((s3 - td), TimestampSeries), + assert_type((s3 - td), TimedeltaSeries), pd.Series, ) check( - assert_type((s3 + td), TimestampSeries), + assert_type((s3 + td), TimedeltaSeries), pd.Series, ) check( - assert_type((s3 * td), TimestampSeries), + assert_type((s3 * td), TimedeltaSeries), pd.Series, ) check( - assert_type((s3 / td), TimestampSeries), + assert_type((s3 / td), Series), pd.Series, ) From 22846708ae53257b2f2455d9f71b9806e77fd9d0 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Sat, 19 Nov 2022 15:29:15 +0530 Subject: [PATCH 10/21] Update test_timefuncs.py --- tests/test_timefuncs.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index c48f98994..d2c31014b 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -1043,9 +1043,9 @@ def timedelta64_and_arithmatic_operator() -> None: s3 = s2 - s1 td = np.timedelta64(1, "M") check(assert_type((s1 - td), TimestampSeries), np.timedelta64) - check(assert_type((s1 + td), Series), np.timedelta64) + check(assert_type((s1 + td), pd.Series[Any]), np.timedelta64) check(assert_type((s1 * td), TimedeltaSeries), np.timedelta64) - check(assert_type((s1 / td), Series), np.timedelta64) + check(assert_type((s1 / td), pd.Series[float]), np.timedelta64) check( assert_type((s3 - td), TimedeltaSeries), pd.Series, @@ -1059,6 +1059,6 @@ def timedelta64_and_arithmatic_operator() -> None: pd.Series, ) check( - assert_type((s3 / td), Series), + assert_type((s3 / td), pd.Series[float]), pd.Series, ) From 9e03f293fc8a89d28319632f8dfda35ba61c21a6 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Sun, 20 Nov 2022 13:02:34 +0530 Subject: [PATCH 11/21] update --- pandas-stubs/core/series.pyi | 4 +++- tests/test_timefuncs.py | 28 ++++++++-------------------- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index 3ccb26b3c..a8cb1ed42 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -1743,6 +1743,8 @@ class TimestampSeries(Series[Timestamp]): # ignore needed because of mypy @property def dt(self) -> TimestampProperties: ... # type: ignore[override] + @overload + def __add__(self, other: Timedelta | np.timedelta64) -> TimedeltaSeries: ... class TimedeltaSeries(Series[Timedelta]): # ignores needed because of mypy @@ -1753,7 +1755,7 @@ class TimedeltaSeries(Series[Timedelta]): @overload def __add__(self, other: Timedelta | np.timedelta64) -> TimedeltaSeries: ... def __radd__(self, pther: Timestamp | TimestampSeries) -> TimestampSeries: ... # type: ignore[override] - def __mul__(self, other: num | np.timedelta64) -> TimedeltaSeries: ... # type: ignore[override] + def __mul__(self, other: num) -> TimedeltaSeries: ... # type: ignore[override] def __sub__( # type: ignore[override] self, other: Timedelta | TimedeltaSeries | TimedeltaIndex | np.timedelta64 ) -> TimedeltaSeries: ... diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index d2c31014b..d9d44267f 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -1042,23 +1042,11 @@ def timedelta64_and_arithmatic_operator() -> None: s2 = pd.Series(data=pd.date_range("1/1/2021", "2/1/2021")) s3 = s2 - s1 td = np.timedelta64(1, "M") - check(assert_type((s1 - td), TimestampSeries), np.timedelta64) - check(assert_type((s1 + td), pd.Series[Any]), np.timedelta64) - check(assert_type((s1 * td), TimedeltaSeries), np.timedelta64) - check(assert_type((s1 / td), pd.Series[float]), np.timedelta64) - check( - assert_type((s3 - td), TimedeltaSeries), - pd.Series, - ) - check( - assert_type((s3 + td), TimedeltaSeries), - pd.Series, - ) - check( - assert_type((s3 * td), TimedeltaSeries), - pd.Series, - ) - check( - assert_type((s3 / td), pd.Series[float]), - pd.Series, - ) + check(assert_type((s1 - td), TimestampSeries), pd.Series, pd.Timestamp) + check(assert_type((s1 + td), TimestampSeries), pd.Series, pd.Timestamp) + check(assert_type((s1 * td), TimedeltaSeries), pd.Series, pd.Timestamp) + check(assert_type((s1 / td), TimestampSeries), pd.Series, pd.Timestamp) + check(assert_type((s3 - td), TimedeltaSeries), pd.Series, pd.Timedelta) + check(assert_type((s3 + td), TimedeltaSeries), pd.Series, pd.Timedelta) + check(assert_type((s3 * td), TimedeltaSeries), pd.Series, pd.Timedelta) + check(assert_type((s3 / td), TimedeltaSeries), pd.Series, np.float) From 258e32a42dd7c7bd857035bfd8849f4fc817aae3 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 22 Nov 2022 03:32:04 +0530 Subject: [PATCH 12/21] update --- pandas-stubs/core/series.pyi | 10 ++++++++-- tests/test_timefuncs.py | 17 +++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index a8cb1ed42..76bfaafec 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -62,6 +62,7 @@ from pandas.core.window.rolling import ( Window, ) from typing_extensions import TypeAlias +from typing_extensions import Never import xarray as xr from pandas._libs.missing import NAType @@ -1743,8 +1744,9 @@ class TimestampSeries(Series[Timestamp]): # ignore needed because of mypy @property def dt(self) -> TimestampProperties: ... # type: ignore[override] - @overload - def __add__(self, other: Timedelta | np.timedelta64) -> TimedeltaSeries: ... + def __add__(self, other: TimedeltaSeries | np.timedelta64) -> TimestampSeries: ... # type: ignore[override] + def __mul__(self, other: TimestampSeries | np.timedelta64) -> Never: ... # type: ignore[override] + def __truediv__(self, other: TimestampSeries | np.timedelta64) -> Never: ... # type: ignore[override] class TimedeltaSeries(Series[Timedelta]): # ignores needed because of mypy @@ -1755,10 +1757,14 @@ class TimedeltaSeries(Series[Timedelta]): @overload def __add__(self, other: Timedelta | np.timedelta64) -> TimedeltaSeries: ... def __radd__(self, pther: Timestamp | TimestampSeries) -> TimestampSeries: ... # type: ignore[override] + @overload def __mul__(self, other: num) -> TimedeltaSeries: ... # type: ignore[override] def __sub__( # type: ignore[override] self, other: Timedelta | TimedeltaSeries | TimedeltaIndex | np.timedelta64 ) -> TimedeltaSeries: ... + def __truediv__(self, other: TimedeltaSeries | np.timedelta64) -> Series[float]: ... # type: ignore[override] + @overload + def __mul__(self, other: TimestampSeries | np.timedelta64) -> Never: ... # type: ignore[override] @property def dt(self) -> TimedeltaProperties: ... # type: ignore[override] diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index d9d44267f..a993191d7 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -5,6 +5,7 @@ from typing import ( TYPE_CHECKING, Any, + NoReturn, Optional, Union, ) @@ -1042,11 +1043,11 @@ def timedelta64_and_arithmatic_operator() -> None: s2 = pd.Series(data=pd.date_range("1/1/2021", "2/1/2021")) s3 = s2 - s1 td = np.timedelta64(1, "M") - check(assert_type((s1 - td), TimestampSeries), pd.Series, pd.Timestamp) - check(assert_type((s1 + td), TimestampSeries), pd.Series, pd.Timestamp) - check(assert_type((s1 * td), TimedeltaSeries), pd.Series, pd.Timestamp) - check(assert_type((s1 / td), TimestampSeries), pd.Series, pd.Timestamp) - check(assert_type((s3 - td), TimedeltaSeries), pd.Series, pd.Timedelta) - check(assert_type((s3 + td), TimedeltaSeries), pd.Series, pd.Timedelta) - check(assert_type((s3 * td), TimedeltaSeries), pd.Series, pd.Timedelta) - check(assert_type((s3 / td), TimedeltaSeries), pd.Series, np.float) + assert_type((s1 - td), TimestampSeries) + assert_type((s1 + td), TimestampSeries) + assert_type((s1 * td), NoReturn) + assert_type((s1 / td), NoReturn) + assert_type((s3 - td), TimedeltaSeries) + assert_type((s3 + td), TimedeltaSeries) + assert_type((s3 * td), Series[Any]) + assert_type((s3 / td), Series[float]) From a5ed64d4e8afade252e7814a777c8b7a755fd2ee Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 22 Nov 2022 17:37:13 +0530 Subject: [PATCH 13/21] update --- pandas-stubs/core/series.pyi | 16 ++++++++-------- tests/test_timefuncs.py | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index 76bfaafec..763cde409 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -1744,27 +1744,27 @@ class TimestampSeries(Series[Timestamp]): # ignore needed because of mypy @property def dt(self) -> TimestampProperties: ... # type: ignore[override] - def __add__(self, other: TimedeltaSeries | np.timedelta64) -> TimestampSeries: ... # type: ignore[override] - def __mul__(self, other: TimestampSeries | np.timedelta64) -> Never: ... # type: ignore[override] - def __truediv__(self, other: TimestampSeries | np.timedelta64) -> Never: ... # type: ignore[override] + def __add__(self, other: TimedeltaSeries | np.timedelta64 | TimestampSeries | Timestamp) -> TimestampSeries: ... # type: ignore[override] + def __mul__(self, other: TimestampSeries | np.timedelta64 | TimedeltaSeries) -> Never: ... # type: ignore[override] + def __truediv__(self, other: TimestampSeries | np.timedelta64 | TimedeltaSeries) -> Never: ... # type: ignore[override] class TimedeltaSeries(Series[Timedelta]): # ignores needed because of mypy @overload # type: ignore[override] - def __add__(self, other: Period) -> PeriodSeries: ... + def __add__(self, other: Period) -> PeriodSeries: ... @overload def __add__(self, other: Timestamp | DatetimeIndex) -> TimestampSeries: ... @overload def __add__(self, other: Timedelta | np.timedelta64) -> TimedeltaSeries: ... def __radd__(self, pther: Timestamp | TimestampSeries) -> TimestampSeries: ... # type: ignore[override] @overload - def __mul__(self, other: num) -> TimedeltaSeries: ... # type: ignore[override] + def __mul__(self, other: TimestampSeries | np.timedelta64 | Timedelta | TimedeltaSeries) -> Never: ... + @overload + def __mul__(self, other: num | TimestampSeries) -> TimedeltaSeries: ... def __sub__( # type: ignore[override] self, other: Timedelta | TimedeltaSeries | TimedeltaIndex | np.timedelta64 ) -> TimedeltaSeries: ... - def __truediv__(self, other: TimedeltaSeries | np.timedelta64) -> Series[float]: ... # type: ignore[override] - @overload - def __mul__(self, other: TimestampSeries | np.timedelta64) -> Never: ... # type: ignore[override] + def __truediv__(self, other: TimedeltaSeries | np.timedelta64 | TimedeltaIndex) -> Series[float]: ... # type: ignore[override] @property def dt(self) -> TimedeltaProperties: ... # type: ignore[override] diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index a993191d7..9550e6470 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -1049,5 +1049,5 @@ def timedelta64_and_arithmatic_operator() -> None: assert_type((s1 / td), NoReturn) assert_type((s3 - td), TimedeltaSeries) assert_type((s3 + td), TimedeltaSeries) - assert_type((s3 * td), Series[Any]) - assert_type((s3 / td), Series[float]) + assert_type((s3 * td), NoReturn) + assert_type((s3 / td), pd.Series[float]) From fee79d685a5501e02bc8b888416fda39e1eebc6e Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 22 Nov 2022 18:51:57 +0530 Subject: [PATCH 14/21] update --- pandas-stubs/core/series.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index 763cde409..998326254 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -1760,7 +1760,7 @@ class TimedeltaSeries(Series[Timedelta]): @overload def __mul__(self, other: TimestampSeries | np.timedelta64 | Timedelta | TimedeltaSeries) -> Never: ... @overload - def __mul__(self, other: num | TimestampSeries) -> TimedeltaSeries: ... + def __mul__(self, other: num | np.timedelta64) -> TimedeltaSeries: ... def __sub__( # type: ignore[override] self, other: Timedelta | TimedeltaSeries | TimedeltaIndex | np.timedelta64 ) -> TimedeltaSeries: ... From fd59d02edd8a670bbabe618761effee762b80880 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 22 Nov 2022 18:53:40 +0530 Subject: [PATCH 15/21] Update series.pyi --- pandas-stubs/core/series.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index 998326254..582c76810 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -1760,7 +1760,7 @@ class TimedeltaSeries(Series[Timedelta]): @overload def __mul__(self, other: TimestampSeries | np.timedelta64 | Timedelta | TimedeltaSeries) -> Never: ... @overload - def __mul__(self, other: num | np.timedelta64) -> TimedeltaSeries: ... + def __mul__(self, other: num) -> TimedeltaSeries: ... def __sub__( # type: ignore[override] self, other: Timedelta | TimedeltaSeries | TimedeltaIndex | np.timedelta64 ) -> TimedeltaSeries: ... From 31db112a901d7ee8f91aa39b2d9325b802867beb Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 22 Nov 2022 21:21:49 +0530 Subject: [PATCH 16/21] Update series.pyi --- pandas-stubs/core/series.pyi | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index 582c76810..23c811992 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -61,8 +61,10 @@ from pandas.core.window.rolling import ( Rolling, Window, ) -from typing_extensions import TypeAlias -from typing_extensions import Never +from typing_extensions import ( + Never, + TypeAlias, +) import xarray as xr from pandas._libs.missing import NAType @@ -1751,16 +1753,18 @@ class TimestampSeries(Series[Timestamp]): class TimedeltaSeries(Series[Timedelta]): # ignores needed because of mypy @overload # type: ignore[override] - def __add__(self, other: Period) -> PeriodSeries: ... + def __add__(self, other: Period) -> PeriodSeries: ... @overload def __add__(self, other: Timestamp | DatetimeIndex) -> TimestampSeries: ... @overload def __add__(self, other: Timedelta | np.timedelta64) -> TimedeltaSeries: ... def __radd__(self, pther: Timestamp | TimestampSeries) -> TimestampSeries: ... # type: ignore[override] + @overload # type: ignore[override] + def __mul__( + self, other: TimestampSeries | np.timedelta64 | Timedelta | TimedeltaSeries + ) -> Never: ... @overload - def __mul__(self, other: TimestampSeries | np.timedelta64 | Timedelta | TimedeltaSeries) -> Never: ... - @overload - def __mul__(self, other: num) -> TimedeltaSeries: ... + def __mul__(self, other: num) -> TimedeltaSeries: ... def __sub__( # type: ignore[override] self, other: Timedelta | TimedeltaSeries | TimedeltaIndex | np.timedelta64 ) -> TimedeltaSeries: ... From f01d3c0d280d59a2bf04828ecbd160eda03a45b0 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 22 Nov 2022 21:32:12 +0530 Subject: [PATCH 17/21] Update test_timefuncs.py --- tests/test_timefuncs.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index 9550e6470..71700e005 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -1043,11 +1043,11 @@ def timedelta64_and_arithmatic_operator() -> None: s2 = pd.Series(data=pd.date_range("1/1/2021", "2/1/2021")) s3 = s2 - s1 td = np.timedelta64(1, "M") - assert_type((s1 - td), TimestampSeries) - assert_type((s1 + td), TimestampSeries) - assert_type((s1 * td), NoReturn) - assert_type((s1 / td), NoReturn) - assert_type((s3 - td), TimedeltaSeries) - assert_type((s3 + td), TimedeltaSeries) - assert_type((s3 * td), NoReturn) - assert_type((s3 / td), pd.Series[float]) + assert_type((s1 - td), TimestampSeries) # type: ignore + assert_type((s1 + td), TimestampSeries) # type: ignore + assert_type((s1 * td), NoReturn) # type: ignore + assert_type((s1 / td), NoReturn) # type: ignore + assert_type((s3 - td), TimedeltaSeries) # type: ignore + assert_type((s3 + td), TimedeltaSeries) # type: ignore + assert_type((s3 * td), NoReturn) # type: ignore + assert_type((s3 / td), pd.Series[float]) # type: ignore From fc41d336051ee295cbdba2d28c5e85a3976eca4f Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Tue, 22 Nov 2022 22:11:38 +0530 Subject: [PATCH 18/21] Update test_timefuncs.py --- tests/test_timefuncs.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index 71700e005..90a2fff9b 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -1043,11 +1043,11 @@ def timedelta64_and_arithmatic_operator() -> None: s2 = pd.Series(data=pd.date_range("1/1/2021", "2/1/2021")) s3 = s2 - s1 td = np.timedelta64(1, "M") - assert_type((s1 - td), TimestampSeries) # type: ignore - assert_type((s1 + td), TimestampSeries) # type: ignore - assert_type((s1 * td), NoReturn) # type: ignore - assert_type((s1 / td), NoReturn) # type: ignore - assert_type((s3 - td), TimedeltaSeries) # type: ignore - assert_type((s3 + td), TimedeltaSeries) # type: ignore - assert_type((s3 * td), NoReturn) # type: ignore - assert_type((s3 / td), pd.Series[float]) # type: ignore + assert_type((s1 - td), TimestampSeries) + assert_type((s1 + td), TimestampSeries) + assert_type((s1 * td), NoReturn) # pyright: ignore + assert_type((s1 / td), NoReturn) # pyright: ignore + assert_type((s3 - td), TimedeltaSeries) + assert_type((s3 + td), TimedeltaSeries) + assert_type((s3 * td), NoReturn) # pyright: ignore + assert_type((s3 / td), pd.Series[float]) From 21992b87fd0ee70c6b29cd1349a1527117b6de8e Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Wed, 23 Nov 2022 03:27:12 +0530 Subject: [PATCH 19/21] update --- pandas-stubs/core/series.pyi | 7 ++++++- tests/test_timefuncs.py | 22 ++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index 23c811992..0a01d8814 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -1746,7 +1746,12 @@ class TimestampSeries(Series[Timestamp]): # ignore needed because of mypy @property def dt(self) -> TimestampProperties: ... # type: ignore[override] - def __add__(self, other: TimedeltaSeries | np.timedelta64 | TimestampSeries | Timestamp) -> TimestampSeries: ... # type: ignore[override] + @overload # type: ignore[override] + def __add__( + self, other: TimedeltaSeries | np.timedelta64 | TimestampSeries + ) -> TimestampSeries: ... + @overload + def __add__(self, other: Timestamp) -> TimestampSeries: ... def __mul__(self, other: TimestampSeries | np.timedelta64 | TimedeltaSeries) -> Never: ... # type: ignore[override] def __truediv__(self, other: TimestampSeries | np.timedelta64 | TimedeltaSeries) -> Never: ... # type: ignore[override] diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index 90a2fff9b..ab1cff10d 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -5,7 +5,6 @@ from typing import ( TYPE_CHECKING, Any, - NoReturn, Optional, Union, ) @@ -15,7 +14,10 @@ import pandas as pd from pandas.core.indexes.numeric import IntegerIndex import pytz -from typing_extensions import assert_type +from typing_extensions import ( + Never, + assert_type, +) from pandas._libs import NaTType from pandas._libs.tslibs import BaseOffset @@ -1043,11 +1045,11 @@ def timedelta64_and_arithmatic_operator() -> None: s2 = pd.Series(data=pd.date_range("1/1/2021", "2/1/2021")) s3 = s2 - s1 td = np.timedelta64(1, "M") - assert_type((s1 - td), TimestampSeries) - assert_type((s1 + td), TimestampSeries) - assert_type((s1 * td), NoReturn) # pyright: ignore - assert_type((s1 / td), NoReturn) # pyright: ignore - assert_type((s3 - td), TimedeltaSeries) - assert_type((s3 + td), TimedeltaSeries) - assert_type((s3 * td), NoReturn) # pyright: ignore - assert_type((s3 / td), pd.Series[float]) + check(assert_type((s1 - td), TimestampSeries), TimestampSeries, pd.Timestamp) + check(assert_type((s1 + td), TimestampSeries), TimestampSeries, pd.Timestamp) + assert_type((s1 * td), Never) # pyright: ignore + assert_type((s1 / td), Never) # pyright: ignore + check(assert_type((s3 - td), TimedeltaSeries), TimedeltaSeries, pd.Timedelta) + check(assert_type((s3 + td), TimedeltaSeries), TimedeltaSeries, pd.Timedelta) + assert_type((s3 * td), Never) # pyright: ignore + check(assert_type((s3 / td), pd.Series[float]), pd.Series[float], float) From cb26631dd64e47d2a7ed903566fd3330c4f0c215 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Wed, 23 Nov 2022 20:24:08 +0530 Subject: [PATCH 20/21] update --- pandas-stubs/core/series.pyi | 2 +- tests/test_timefuncs.py | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index 0a01d8814..91923f9eb 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -1751,7 +1751,7 @@ class TimestampSeries(Series[Timestamp]): self, other: TimedeltaSeries | np.timedelta64 | TimestampSeries ) -> TimestampSeries: ... @overload - def __add__(self, other: Timestamp) -> TimestampSeries: ... + def __add__(self, other: Timestamp) -> Never: ... def __mul__(self, other: TimestampSeries | np.timedelta64 | TimedeltaSeries) -> Never: ... # type: ignore[override] def __truediv__(self, other: TimestampSeries | np.timedelta64 | TimedeltaSeries) -> Never: ... # type: ignore[override] diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index ab1cff10d..eeb0ff795 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -1040,16 +1040,17 @@ def test_dateoffset_freqstr() -> None: check(assert_type(offset.freqstr, str), str) -def timedelta64_and_arithmatic_operator() -> None: +def test_timedelta64_and_arithmatic_operator() -> None: s1 = pd.Series(data=pd.date_range("1/1/2020", "2/1/2020")) s2 = pd.Series(data=pd.date_range("1/1/2021", "2/1/2021")) s3 = s2 - s1 td = np.timedelta64(1, "M") - check(assert_type((s1 - td), TimestampSeries), TimestampSeries, pd.Timestamp) - check(assert_type((s1 + td), TimestampSeries), TimestampSeries, pd.Timestamp) - assert_type((s1 * td), Never) # pyright: ignore - assert_type((s1 / td), Never) # pyright: ignore - check(assert_type((s3 - td), TimedeltaSeries), TimedeltaSeries, pd.Timedelta) - check(assert_type((s3 + td), TimedeltaSeries), TimedeltaSeries, pd.Timedelta) - assert_type((s3 * td), Never) # pyright: ignore - check(assert_type((s3 / td), pd.Series[float]), pd.Series[float], float) + check(assert_type((s1 - td), "TimestampSeries"), pd.Series, pd.Timestamp) + check(assert_type((s1 + td), "TimestampSeries"), pd.Series, pd.Timestamp) + check(assert_type((s3 - td), "TimedeltaSeries"), pd.Series, pd.Timedelta) + check(assert_type((s3 + td), "TimedeltaSeries"), pd.Series, pd.Timedelta) + check(assert_type((s3 / td), "pd.Series[float]"), pd.Series, float) + if TYPE_CHECKING_INVALID_USAGE: + assert_type((s1 * td), Never) # pyright: ignore + assert_type((s1 / td), Never) # pyright: ignore + assert_type((s3 * td), Never) # pyright: ignore From ca750991d5340b54f10fe78c8e4533547e119188 Mon Sep 17 00:00:00 2001 From: ramvikrams Date: Wed, 23 Nov 2022 20:45:18 +0530 Subject: [PATCH 21/21] Update test_timefuncs.py --- tests/test_timefuncs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index eeb0ff795..b97369466 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -263,7 +263,7 @@ def fail_on_adding_two_timestamps() -> None: if TYPE_CHECKING_INVALID_USAGE: ssum: pd.Series = s1 + s2 # TODO both: ignore[operator] ts = pd.Timestamp("2022-06-30") - tsum: pd.Series = s1 + ts # TODO both: ignore[operator] + tsum: pd.Series = s1 + ts # pyright: ignore def test_dtindex_tzinfo() -> None: