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 #956

Closed
headtr1ck opened this issue Jul 1, 2024 · 1 comment · Fixed by #959
Closed

Switch to_timedelta argument type from list to Sequence #956

headtr1ck opened this issue Jul 1, 2024 · 1 comment · Fixed by #959
Labels
good first issue Timedelta Code related to Timedelta

Comments

@headtr1ck
Copy link

Describe the bug
to_timedelta uses a list of a union argument type.
This will raise false positive errors when passing a list of a single type because list is invariant.

To Reproduce

import pandas as pd

pd.to_timedelta(["1 day"])

produces:

error: Argument 1 to "to_timedelta" has incompatible type "list[str]"; expected "Union[Sequence[Union[float, timedelta]], list[Union[str, float, timedelta]], tuple[Union[str, float, timedelta], ...], range, Union[ExtensionArray, ndarray[Any, Any]], Index[Any]]" [arg-type]
note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
note: Consider using "Sequence" instead, which is covariant

Please complete the following information:

  • OS: Win
  • OS Version 10
  • python 3.9.7
  • version of type checker mypy 1.8.0
  • version of installed pandas-stubs 2.2.2.240603
@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Jul 1, 2024

Thanks for the report. I agree - we can change list to Sequence at

| list[str | float | timedelta]

PR with test welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Timedelta Code related to Timedelta
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants