Skip to content

Summing nanoseconds time delta to timestamp #43764

Closed
@deponovo

Description

@deponovo

  • 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 master branch of pandas.

Reproducible Example

import pandas as pd
res1 = (pd.Timestamp(1001) == pd.Timedelta(seconds=1e-9) + pd.Timestamp(1000))  # False, but should be True
res2 = (pd.Timestamp(1001) == pd.Timestamp(1) + pd.Timedelta(seconds=1000e-9))  # True
res1 == res2  # False, should be True
# this sum works properly `pd.Timestamp(1) + pd.Timedelta(nanoseconds=1)`

Issue Description

Adding Timedeltas that have nanoseconds defined as a float do not work properly for timedelta values in the [1-999] range.
This report is a result of this SO question

Expected Behavior

all([pd.Timestamp(1000 + x) == (pd.Timedelta(seconds=x*1e-9) + pd.Timestamp(1000)) for x in range(1000)]) should be True

Or any equivalent not using the explicit default nanoseconds unit or the nanoseconds keyword as in: pd.Timedelta(1) or pd.Timedelta(nanoseconds=1)

Installed Versions

INSTALLED VERSIONS

commit : c7f7443
python : 3.8.5.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.18362
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 12, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : de_DE.cp1252
pandas : 1.3.1
numpy : 1.20.3
pytz : 2021.1
dateutil : 2.8.1
pip : 21.1.2
setuptools : 49.6.0.post20210108
Cython : None
pytest : 6.2.4
hypothesis : None
sphinx : 4.0.2
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.6.3
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.1
IPython : 7.24.1
pandas_datareader: None
bs4 : None
bottleneck : 1.3.2
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.4.1
numexpr : 2.7.3
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.6.3
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions