Skip to content
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

Merged
merged 6 commits into from
Jul 16, 2024

Conversation

loicdiridollou
Copy link
Contributor

@loicdiridollou loicdiridollou commented Jul 12, 2024

Should fix the issue in #956 with allowing the sequence of string type, I was not sure about the assert_type step above, please feel free to guide me on that one.

Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

Please make changes as indicated, and then I will star the CI process to see if there are any other issues.

Comment on lines 34 to 35
Sequence[str | float | timedelta]
| list[str | float | timedelta]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Combine these to one item of Sequence[str | float | timedelta]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed Sequence is encompassing list so might as well.

Comment on lines 145 to 149
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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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)

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 for the feedback and the clarity!

@loicdiridollou loicdiridollou requested a review from Dr-Irv July 15, 2024 18:20
@@ -31,8 +31,7 @@ def to_timedelta(
@overload
def to_timedelta(
arg: (
Sequence[float | timedelta]
| list[str | float | timedelta]
Sequence[str | float | timedelta]
Copy link
Collaborator

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 to

Suggested change
Sequence[str | float | timedelta]
SequenceNotStr | Sequence[float | timedelta]

You can import SequenceNotStr from _typing

Also, you should set up your environment and test locally.

Copy link
Contributor Author

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 both Sequence.
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!

Copy link
Contributor Author

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.

@loicdiridollou loicdiridollou requested a review from Dr-Irv July 15, 2024 20:50
Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

One small change. It passed the CI, so it's pretty close.

tests/test_timefuncs.py Outdated Show resolved Hide resolved
@loicdiridollou loicdiridollou requested a review from Dr-Irv July 15, 2024 23:42
Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

@Dr-Irv Dr-Irv merged commit 48ca4b0 into pandas-dev:main Jul 16, 2024
13 checks passed
@loicdiridollou loicdiridollou deleted the ld_issue_956 branch July 16, 2024 23:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switch to_timedelta argument type from list to Sequence
2 participants