-
-
Notifications
You must be signed in to change notification settings - Fork 150
feat(arithmetic): ✖️ multiplication #1397
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
base: main
Are you sure you want to change the base?
Conversation
Will await your ping for the review. |
f1acc37
to
19191a4
Compare
19191a4
to
9c802b4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests/test_timefuncs.py
Outdated
def test_fail_on_adding_two_timestamps() -> None: | ||
s1 = pd.Series(pd.to_datetime(["2022-05-01", "2022-06-01"])) | ||
s2 = pd.Series(pd.to_datetime(["2022-05-15", "2022-06-15"])) | ||
if TYPE_CHECKING_INVALID_USAGE: | ||
ssum = s1 + s2 # type: ignore[operator] # pyright: ignore[reportOperatorIssue] | ||
ts = pd.Timestamp("2022-06-30") | ||
tsum = s1 + ts # type: ignore[operator] # pyright: ignore[reportOperatorIssue] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now in tests/series/arithmetic/timestamp/test_add.py
std = (df["x"] < df["y"]) * pd.Timedelta(10, "minutes") | ||
check(assert_type(std, "pd.Series[pd.Timedelta]"), pd.Series, pd.Timedelta) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests/series/arithmetic/bool/test_mul.py
r3 = td + ts | ||
check(assert_type(r3, "pd.Series[pd.Timestamp]"), pd.Series, pd.Timestamp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests/series/arithmetic/timedelta/test_add.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should tests be added that make sure that if a str
is used in multiplication, we catch that as invalid? And that both Series[str]
and Index[str]
with multiplication are caught as well?
This is in pretty good shape. I think you are missing some tests on Index[Any]
with multiplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why you have an empty file here, although I would assume some tests are necessary???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in c8e0105
def left() -> "pd.Index[pd.Timedelta]": | ||
"""left operand""" | ||
# pandas-dev/pandas#62524 | ||
lo = pd.Index([1]) * [timedelta(seconds=1)] # left operand | ||
return check(assert_type(lo, "pd.Index[pd.Timedelta]"), pd.Index, timedelta) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should be testing this. pd.Index[Timedelta]
should only hold Timedelta
objects, not python timedelta
objects. pd.Index([timedelta(seconds=1)])
creates this: TimedeltaIndex(['0 days 00:00:01'], dtype='timedelta64[ns]', freq=None)
and that's the normal supported usage of timedelta
in an index.
I'd even question whether we should have any operations supporting pd.Index[pd.Timedelta]
, because that really is a TimedeltaIndex
.
Actually, thinking about it more, I don't think we should have Index[Timedelta]
or Index[Timestamp]
in the stubs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is in pandas-dev/pandas#62524, where I found out that pandas
indeed creates Index[Timedelta]
when one does pd.Index([1]) * [timedelta(days=1)]
, which is quite unintuitive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests for Series[str] * num and Index[str] * num added in 6cf48fc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in c8e0105
def left() -> "pd.Index[pd.Timedelta]": | ||
"""left operand""" | ||
# pandas-dev/pandas#62524 | ||
lo = pd.Index([1]) * [timedelta(seconds=1)] # left operand | ||
return check(assert_type(lo, "pd.Index[pd.Timedelta]"), pd.Index, timedelta) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is in pandas-dev/pandas#62524, where I found out that pandas
indeed creates Index[Timedelta]
when one does pd.Index([1]) * [timedelta(days=1)]
, which is quite unintuitive.
/pyright_strict |
/pandas_nightly |
/mypy_nightly |
In
|
__mul__
,mul
, etc. inSeries
TimedeltaIndex
andDatetimeIndex
#1378