You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The pandas timedelta class has less than expected minimum and maximum timedeltas. The range is [-99999, 99999] days instead of [-999999999, 999999999] days
Code Sample
expected_max_days=999999999# 9 ninesmax_days=99999# 5 ninesprint("1. Expected minimum and maximum")
print(pd.Timedelta.min, '\t', pd.Timedelta.max)
print(datetime.timedelta.min, '\t', datetime.timedelta.max)
print("\n2. Expected min and max as pd.Timedelta objects")
print(pd.Timedelta(pd.Timedelta.min), '\t', pd.Timedelta(pd.Timedelta.max)) # overflow, no errorprint("\n3. True min and max (in days) and comparing with numpy")
print(np.timedelta64(-max_days, 'D'), '\t\t', np.timedelta64(max_days, 'D'))
print(pd.Timedelta(-max_days, 'D'), '\t', pd.Timedelta(max_days, 'D'))
print("\n4. Expected min and max (in days) and comparing with numpy")
print(np.timedelta64(-expected_max_days, 'D'), '\t', np.timedelta64(expected_max_days, 'D'))
print(pd.Timedelta(-expected_max_days, 'D'), '\t', pd.Timedelta(expected_max_days, 'D')) # overflowError
Expected Output
1. Expected minimum and maximum
-999999999 days, 0:00:00 999999999 days, 23:59:59.999999
-999999999 days, 0:00:00 999999999 days, 23:59:59.999999
2. Expected min and max as pd.Timedelta objects
52654 days 06:07:35.539769 -52654 days +17:52:24.460229
3. True min and max (in days) and comparing with numpy
-99999 days 99999 days
-99999 days +00:00:00 99999 days 00:00:00
4. Expected min and max (in days) and comparing with numpy
-999999999 days 999999999 days
---------------------------------------------------------------------------
OverflowError Traceback (most recent call last)
<ipython-input-104-9f01918ed468> in <module>()
15 print("\n4. Expected min and max (in days) and comparing with numpy")
16 print(np.timedelta64(-expected_max_days, 'D'), '\t', np.timedelta64(expected_max_days, 'D'))
---> 17 print(pd.Timedelta(-expected_max_days, 'D'), '\t', pd.Timedelta(expected_max_days, 'D')) # overflowError
pandas/tslib.pyx in pandas.tslib.Timedelta.__new__ (pandas/tslib.c:43558)()
pandas/tslib.pyx in pandas.tslib.convert_to_timedelta64 (pandas/tslib.c:53419)()
pandas/tslib.pyx in pandas.tslib.cast_from_unit (pandas/tslib.c:58740)()
OverflowError: Python int too large to convert to C long
The problem is illustrated at points 2 (silent overflow) and 4(overflow error)
Unlike in numpy, pandas.Timdelta always uses nanosecond precision, so anything more than about 100000 days cannot be represented. Something does seem to be going wrong with the numeric overflow, though.
In [8]: pd.Timedelta(np.iinfo(np.int64).max)
Out[8]: Timedelta('106751 days 23:47:16.854775')
In [9]: pd.Timedelta(np.iinfo(np.int64).min)
Out[9]: NaT
In [10]: pd.Timedelta(np.iinfo(np.int64).min+1)
Out[10]: Timedelta('-106752 days +00:12:43.145224')
The pandas timedelta class has less than expected minimum and maximum timedeltas. The range is
[-99999, 99999]
days instead of [-999999999, 999999999]
daysCode Sample
Expected Output
The problem is illustrated at points
2
(silent overflow) and4
(overflow error)output of
pd.show_versions()
I get similar results on python
3.5.1
.The text was updated successfully, but these errors were encountered: