BUG: support non-nanos Timedelta objects in Python C API #54682
Labels
Bug
Closing Candidate
May be closeable, needs more eyeballs
Non-Nano
datetime64/timedelta64 with non-nanosecond resolution
Timedelta
Timedelta data type
See apache/arrow#37291 for context.
In the Timedelta constructor, we have:
pandas/pandas/_libs/tslibs/timedeltas.pyx
Lines 953 to 964 in 43691a2
and then the relevant note in the seconds attribute:
pandas/pandas/_libs/tslibs/timedeltas.pyx
Lines 1103 to 1104 in 43691a2
So it is a known issue that those C API functions no longer will work with Timedeltas of second or millisecond resolution.
Pyarrow is exactly using those C APIs, which are now silently incorrect for second and millisecond resolution Timedeltas. While pyarrow should certainly adapt to properly support pandas.Timedelta (especially for cases outside the range of datetime.timedelta), I think it might be safer for pandas to ensure those C APIs keep working (I think pyarrow will certainly not be the only one using those).
It seems possible to me to at least set those for the cases where they are within the range of datetime.timedelta (which will be by far the large majority of cases, since it goes up to 999999999 days, which is more than 2 million years if I did the math correctly), at the cost of making the constructor a bit more costly.
cc @jbrockmendel
The text was updated successfully, but these errors were encountered: