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

pd.Timedelta should also accept float values #1015

Open
5j9 opened this issue Oct 14, 2024 · 2 comments
Open

pd.Timedelta should also accept float values #1015

5j9 opened this issue Oct 14, 2024 · 2 comments
Labels
good first issue Timedelta Code related to Timedelta

Comments

@5j9
Copy link

5j9 commented Oct 14, 2024

The value parameter of Timedelta currently has the following type-hint:

value: str | int | Timedelta | timedelta | np.timedelta64 = ...,

I think it should also accept float, so that type checkers won't complain on following code snippet:

import pandas as pd
pd.Timedelta(3.5, 'hours')
Argument of type "float" cannot be assigned to parameter "value" of type "str | int | Timedelta | timedelta | timedelta64" in function "__new__"
  Type "float" is not assignable to type "str | int | Timedelta | timedelta | timedelta64"
    "float" is not assignable to "str"
    "float" is not assignable to "int"
    "float" is not assignable to "Timedelta"
    "float" is not assignable to "timedelta"
    "float" is not assignable to "timedelta64"
Pylance[reportArgumentType](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportArgumentType)
@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Oct 14, 2024

Thanks for the report. The docs at https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Timedelta.html#pandas.Timedelta have the same issue, so can you raise an issue there as well?

PR with tests welcome.

@Dr-Irv Dr-Irv added good first issue Timedelta Code related to Timedelta labels Oct 14, 2024
@5j9
Copy link
Author

5j9 commented Oct 15, 2024

pandas-dev/pandas#60044

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

No branches or pull requests

2 participants