Description
-
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
import pandas as pd
# create 1us Timedelta - it can be successfully converted to float
a = pd.Timedelta("1us")
print(a)
print(a.total_seconds())
# create 500ns Timedelta - it is not converted successfully to float - result is zero
b = pd.Timedelta("500ns")
print(b)
print(b.total_seconds())
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:
0 days 00:00:00.000001
1e-06
0 days 00:00:00.000000
5e-07
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:
0 days 00:00:00.000001
1e-06
0 days 00:00:00.000000500
0.0
now the timedelta representation is fixed, but its float value is 0.0 insteaad of 5e-7
Expected Output
0 days 00:00:00.000001
1e-06
0 days 00:00:00.000000500
5e-7
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