BUG: comparing pd.Timedelta with timedelta.max fails #49021
Labels
Bug
Needs Triage
Issue that has not been reviewed by a pandas team member
Timedelta
Timedelta data type
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
It looks like
timedelta.max
is too large to be represented as apd.Timedelta
.As a workaround, I convert the pandas
Timedelta
to adatetime.timedelta
instead:The issue also occurs when comparing a
pd.Timedelta
totimedelta.min
.Expected Behavior
In case this could be easily addressed in a fix, I'd be happy to work on it. It looks like the relevant part of the Pandas codebase is
timedeltas.pyx
, which already has a# TODO: watch out for overflows
. One idea would be to except theOverflowError
and do the comparison withdatetime.timedelta
objects (by convertingself.value
to adatetime.timedelta
rather thanots.value
to apd.Timedelta
). I believe this would imply losing the nanosecond precision (but keeping microsecond precision) when comparingpd.Timedelta
values todatetime.timedelta
values larger thanpd.Timedelta.max
.In case it is not easily fixed, perhaps we could consider what a useful addition would be to the documentation of
pd.Timedelta
and/orpd.Timedelta.max
.Installed Versions
INSTALLED VERSIONS
commit : 87cfe4e
python : 3.9.9.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.11-76051511-generic
Version : #202112220937
164018548121.04~b3a2c21-Ubuntu SMP Mon Jan 3 16:5machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.5.0
numpy : 1.21.5
pytz : 2021.3
dateutil : 2.8.2
setuptools : 62.0.0
pip : 22.2.2
Cython : None
pytest : 6.2.5
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : 1.1
pymysql : None
psycopg2 : 2.9.2
jinja2 : 3.0.3
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : 0.55.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.7.3
snappy : None
sqlalchemy : 1.4.28
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None
The text was updated successfully, but these errors were encountered: