Precision error when using Timedelta.total_seconds method · Issue #19458 · pandas-dev/pandas (original) (raw)
Code Sample
import pandas as pd block = pd.Timedelta('30S') block.total_seconds() 30.000000000000004
Problem description
When using Timedelta.total_seconds
I sometime encounter a small precision error (1e-15), which can be significant in some scenarios (for instance when later dividing the results and expecting an integer). The workaround is to always use a rounding method, which makes the code cumbersome.
Expected Output
A float or integer representing the seconds precisely.
Output of pd.show_versions()
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 2.7.13.final.0
python-bits: 64
OS: Linux
OS-release: 4.9.0-5-amd64
machine: x86_64
processor:
byteorder: little
LC_ALL: en_US.utf8
LANG: en_US.UTF-8
LOCALE: None.None
pandas: 0.22.0
pytest: None
pip: 9.0.1
setuptools: 38.4.0
Cython: None
numpy: 1.14.0
scipy: None
pyarrow: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.999999999
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None