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

ENH: support for non-nanosecond precision in pd.Timedelta #59389

Open
1 of 3 tasks
veenstrajelmer opened this issue Aug 2, 2024 · 3 comments
Open
1 of 3 tasks

ENH: support for non-nanosecond precision in pd.Timedelta #59389

veenstrajelmer opened this issue Aug 2, 2024 · 3 comments
Labels
Closing Candidate May be closeable, needs more eyeballs Enhancement Non-Nano datetime64/timedelta64 with non-nanosecond resolution

Comments

@veenstrajelmer
Copy link

veenstrajelmer commented Aug 2, 2024

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

When converting matlab datenums, I would expect this should be easily possible with pd.Timedelta(), however, several approaches give different errors:

import pandas as pd
# raises OutOfBoundsTimedelta: seconds=62703763200000000000, milliseconds=0, microseconds=0, nanoseconds=0
pd.Timedelta(days=725738)
# raises OutOfBoundsTimedelta: Cannot cast 725738 from D to 'ns' without overflow.
pd.to_timedelta(725738, unit='days')

I expect this is because of the nanosecond accuracy. Matlab dates are in days (dtype float) and I would be happy with microsecond (or less) precision. pd.date_range() and pd.Timestamp() now support non-nanosecond accuracy. Would this also be possible with pd.Timedelta()?

Feature Description

Add support for non-nanosecond accuracy for pd.Timedelta()

Alternative Solutions

It is possible to convert matlab datenums to pandas datetimes with the following approach from https://stackoverflow.com/a/49135037/5578371:

import pandas as pd
import numpy as np
time_wl = pd.to_datetime(np.array([725738])-719529, unit='D').round('s')

Gives: DatetimeIndex(['1987-01-01'], dtype='datetime64[ns]', freq=None)

Additional Context

No response

@veenstrajelmer veenstrajelmer added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 2, 2024
@rhshadrach
Copy link
Member

Thanks for the request. For pd.to_timedelta, I believe this is a duplicate of #49060.

@jbrockmendel - should pd.Timedelta also be added to #49060?

@rhshadrach rhshadrach added the Non-Nano datetime64/timedelta64 with non-nanosecond resolution label Aug 4, 2024
@veenstrajelmer
Copy link
Author

Thanks for the reply. I actually found that issue in my search, but since it was so old I wrongly assumed it was pre 2.0. I will read better in the future. Either way, feel free to close this issue if needed.

@jbrockmendel
Copy link
Member

I dont think we should add the keyword to pd.Timedelta, no. The particular construction from the OP is a tough case; something like pd.Timedelta(np.timedelta64(N, "D")) should work as expected

@rhshadrach rhshadrach added Closing Candidate May be closeable, needs more eyeballs and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closing Candidate May be closeable, needs more eyeballs Enhancement Non-Nano datetime64/timedelta64 with non-nanosecond resolution
Projects
None yet
Development

No branches or pull requests

3 participants