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

DOC: The value parameter of pandas.Timedelta can also accept float #60044

Open
1 task done
5j9 opened this issue Oct 15, 2024 · 5 comments · May be fixed by #60058
Open
1 task done

DOC: The value parameter of pandas.Timedelta can also accept float #60044

5j9 opened this issue Oct 15, 2024 · 5 comments · May be fixed by #60058
Labels
Docs Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@5j9
Copy link
Contributor

5j9 commented Oct 15, 2024

Pandas version checks

  • I have checked that the issue still exists on the latest versions of the docs on main here

Location of the documentation

https://pandas.pydata.org/docs/dev/reference/api/pandas.Timedelta.html#pandas.Timedelta

Documentation problem

It currently states:

value : Timedelta, timedelta, np.timedelta64, str, or int

There is no float.

Suggested fix for documentation

Add float, to accepted types.

There already exists a code branch for float values so this should not be a problem:

elif is_integer_object(value) or is_float_object(value):

@5j9 5j9 added Docs Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 15, 2024
@ZKaoChi
Copy link

ZKaoChi commented Oct 15, 2024

Hello! I tested this method and I found that although pd.Timedelta can accept float values numbers, the result only takes the integer part. For example

print(pd.Timedelta(3651015))
0 days 00:00:00.003651015
print(pd.Timedelta(365.1015))
0 days 00:00:00.000000365

@5j9
Copy link
Contributor Author

5j9 commented Oct 15, 2024

@ZKaoChi Hi! Thanks for looking into this.

The default unit value is ns, and I think that's the lowest resolution supported. So that might be expected for the default ns unit. But if you pass any other unit, the fractional part will matter:

In [11]: pd.Timedelta(3.5, 'hours')
Out[11]: Timedelta('0 days 03:30:00')

In [12]: pd.Timedelta(3, 'hours')
Out[12]: Timedelta('0 days 03:00:00')

In [15]: pd.Timedelta(3, 'W')
Out[15]: Timedelta('21 days 00:00:00')

In [16]: pd.Timedelta(3.5, 'W')
Out[16]: Timedelta('24 days 12:00:00')

In [17]: pd.Timedelta(3.5, 'microseconds')
Out[17]: Timedelta('0 days 00:00:00.000003500')

In [18]: pd.Timedelta(3, 'microseconds')
Out[18]: Timedelta('0 days 00:00:00.000003')

@yuanx749
Copy link
Contributor

Agreed. datetime.timedelta also accepts float, and Timedelta is the pandas equivalent of it.

@ZKaoChi
Copy link

ZKaoChi commented Oct 16, 2024

@5j9 Thanks for your correction! It was my oversight not to notice the units of the data.

ZKaoChi added a commit to ZKaoChi/pandas that referenced this issue Oct 16, 2024
ZKaoChi added a commit to ZKaoChi/pandas that referenced this issue Oct 16, 2024
@ZKaoChi ZKaoChi linked a pull request Oct 16, 2024 that will close this issue
1 task
@ZKaoChi
Copy link

ZKaoChi commented Oct 16, 2024

I'm new and I wanna solve this issue, but my pre-commit.ci - pr was failed because of cython-lint. Coule anyone please teache me how to deal with it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants