-
-
Notifications
You must be signed in to change notification settings - Fork 132
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
Switch to_timedelta argument type from list to Sequence #959
Changes from 1 commit
36dfe7f
485ddd0
a143dcd
cffcec6
e6fb19c
5eff82e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ def to_timedelta( | |
@overload | ||
def to_timedelta( | ||
arg: ( | ||
Sequence[float | timedelta] | ||
Sequence[str | float | timedelta] | ||
| list[str | float | timedelta] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Combine these to one item of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed Sequence is encompassing list so might as well. |
||
| tuple[str | float | timedelta, ...] | ||
| range | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,6 +140,15 @@ def test_timedelta_series_arithmetic() -> None: | |
r4: pd.TimedeltaIndex = tds1 / 10.2 | ||
|
||
|
||
def test_timedelta_series_string() -> None: | ||
tds1: pd.TimedeltaIndex = pd.to_timedelta(["1 day"]) | ||
td1: pd.Timedelta = pd.Timedelta("2 days") | ||
r1: pd.TimedeltaIndex = tds1 + td1 | ||
r2: pd.TimedeltaIndex = tds1 - td1 | ||
r3: pd.TimedeltaIndex = tds1 * 4.3 | ||
r4: pd.TimedeltaIndex = tds1 / 10.2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need these tests here. You do need to do the test as follows: check(assert_type(pd.to_timedelta(["1 day"]), pd.TimedeltaIndex), pd.TimedeltaIndex) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the feedback and the clarity! |
||
|
||
|
||
def test_timestamp_timedelta_series_arithmetic() -> None: | ||
ts1 = pd.to_datetime(pd.Series(["2022-03-05", "2022-03-06"])) | ||
assert isinstance(ts1.iloc[0], 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.
The CI is failing because a plain string will match
Sequence[str]
. So you should change this toYou can import
SequenceNotStr
from_typing
Also, you should set up your environment and test locally.
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.
Great that you are confirming my initial solution,
'1 day'
and['1 day']
are bothSequence
.I forgot to rerun locally when I pushed the feedback last time, should be good now.
Thanks for all the insights on my first PR here!
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 had to force the typehint in the test, let me know if this is in the spirit.