BUG: total_seconds() method returns zero for timedeltas smaller then 1 microsecond #40946
Closed
3 tasks
Labels
Bug
Regression
Functionality that used to work in a prior pandas version
Timedelta
Timedelta data type
Milestone
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
Problem description
Starting with version 1.1.0 Timedelta objects that represent time shorter than 1 microsecond cannot be successfully converted to float -> the result is always zero. This is also present on the current version (1.2.4). when trying same code on pandas 1.0.5, situation is the opposite: Printed output for timedeltas smaller then 1us is bad; it shows all zeros, but converted float value is valid.
Output in pandas 1.0.5:
third line has unexpected value, but it doesn't affect float conversion, as can be seen in the 4th line.
Output in pandas 1.2.4:
now the timedelta representation is fixed, but its float value is 0.0 insteaad of 5e-7
Expected Output
I am also interested in contributing and helping to fix this issue, if that is needed.
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : 2cb9652
python : 3.8.4.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19041
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 9, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : Serbian (Latin)_Serbia.1250
pandas : 1.2.4
numpy : 1.20.2
pytz : 2021.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 47.1.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: