Skip to content

dt.total_seconds() stores float with appending 0.00000000000001 #34290

Closed
@sjvdm

Description

@sjvdm

Simple test to show that if I have two datetime columns and use dt.total_seconds() to calc the difference, values are stored with an offset of 0.00000000000001.

print(pd.__version__)
print(pd.show_versions())
1.0.3

INSTALLED VERSIONS
------------------
commit           : None
python           : 3.8.0.final.0
python-bits      : 64
OS               : Linux
OS-release       : 3.10.0-1062.18.1.el7.x86_64
machine          : x86_64
processor        : x86_64
byteorder        : little
LC_ALL           : None
LANG             : en_US.UTF-8
LOCALE           : en_US.UTF-8

pandas           : 1.0.3
numpy            : 1.18.3
pytz             : 2019.3
dateutil         : 2.8.1
pip              : 20.0.2
setuptools       : 41.4.0
Cython           : 0.29.16
pytest           : 5.4.1
hypothesis       : None
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : None
html5lib         : None
pymysql          : None
psycopg2         : None
jinja2           : 2.11.2
IPython          : 7.13.0
pandas_datareader: None
bs4              : None
bottleneck       : None
fastparquet      : None
gcsfs            : None
lxml.etree       : None
matplotlib       : 3.2.1
numexpr          : 2.7.1
odfpy            : None
openpyxl         : 3.0.3
pandas_gbq       : None
pyarrow          : None
pytables         : None
pytest           : 5.4.1
pyxlsb           : None
s3fs             : None
scipy            : 1.4.1
sqlalchemy       : 1.3.16
tables           : 3.6.1
tabulate         : None
xarray           : None
xlrd             : None
xlwt             : None
xlsxwriter       : None
numba            : None

iPython code:

import pandas as pd
import datetime

data = {'start':datetime.datetime(2020,1,1,12),
       'end':datetime.datetime(2020,1,1,12,2) 
       }

df = pd.DataFrame(data,index=[0])

#try to parse to pd.to_datetime
df['end'] = pd.to_datetime(df['end'])
df['start'] = pd.to_datetime(df['start'])

print('print calc differences')
print((df['end'] - df['start']).dt.total_seconds())
print((df['end'] - df['start']).dt.total_seconds().values[0])
print('')

print('testing on normal float')
print(float(120))
print('')

Output:

print calc differences
0    120.0
dtype: float64
120.00000000000001

testing on normal float
120.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions