Skip to content

added np.timedelta64 for series arithmatic methods #432

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 21 commits into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to put all the definitions of the same methods that have overloads together. Move lines 1766-1767 to after line 1761

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks sir

Copy link
Contributor Author

@ramvikrams ramvikrams Nov 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error: Signature of "__mul__" incompatible with supertype "Series" [override] this is the last mypy error it doesn't go if I add # type: ignore[override] from line number 1760

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to put all the definitions of the same methods that have overloads together. Move lines 1766-1767 to after line 1761

done sir

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error: Signature of "__mul__" incompatible with supertype "Series" [override] this is the last mypy error it doesn't go if I add # type: ignore[override] from line number 1760

It's OK to put in the # type: ignore[override] in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error: Signature of "__mul__" incompatible with supertype "Series" [override] this is the last mypy error it doesn't go if I add # type: ignore[override] from line number 1760

It's OK to put in the # type: ignore[override] in this case.

then it shows this error error: Unused "type: ignore" comment

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check the line numbers that the error is reported on

Copy link
Contributor Author

@ramvikrams ramvikrams Nov 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is on line 1760 the initial error is error: Signature of "__mul__" incompatible with supertype "Series" [override] and after I add # type: ignore[override] the initial error still remains

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Push your current code and I can take a look at the CI logs

@property
def dt(self) -> TimedeltaProperties: ... # type: ignore[override]

Expand Down
17 changes: 9 additions & 8 deletions tests/test_timefuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import (
TYPE_CHECKING,
Any,
NoReturn,
Optional,
Union,
)
Expand Down Expand Up @@ -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])