Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Timestamp.unit should reflect changes in components after Timestamp.replace #57749

Open
2 of 3 tasks
wjsi opened this issue Mar 6, 2024 · 2 comments
Open
2 of 3 tasks
Assignees
Labels
Bug Non-Nano datetime64/timedelta64 with non-nanosecond resolution

Comments

@wjsi
Copy link
Contributor

wjsi commented Mar 6, 2024

Pandas version checks

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

Reproducible Example

import datetime
import pandas as pd

ts = pd.Timestamp("2023-07-15 23:08:12.134567123")
print(ts)  # shows Timestamp('2023-07-16 23:08:12.134567123')
ts2 = pd.Timestamp(datetime.datetime.utcfromtimestamp(int(ts.timestamp())))
ts2 = ts2.replace(microsecond=ts.microsecond, nanosecond=ts.nanosecond)
print(ts2)  # shows Timestamp('2023-07-16 23:08:12.134567123')
assert ts == ts2  # fails

Issue Description

While repr(ts) and repr(ts2) are equal, direct comparison fails.

Expected Behavior

ts and ts2 shall be equal.

Installed Versions

INSTALLED VERSIONS

commit : bdc79c1
python : 3.9.16.final.0
python-bits : 64
OS : Darwin
OS-release : 22.5.0
Version : Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:22 PDT 2023; root:xnu-8796.121.3~7/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : zh_CN.UTF-8
LOCALE : zh_CN.UTF-8

pandas : 2.2.1
numpy : 1.25.2
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 61.2.0
pip : 22.3.1
Cython : 3.0.2
pytest : 8.0.2
hypothesis : 6.46.5
sphinx : 7.2.6
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 8.1.1
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : 1.3.8
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.7.2
numba : None
numexpr : 2.8.4
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : 11.0.0
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.11.1
sqlalchemy : 2.0.19
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : 0.21.0
tzdata : 2023.3
qtpy : None
pyqt5 : None

@wjsi wjsi added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 6, 2024
@mroeschke
Copy link
Member

Thanks for the report. This is due to the unit attributes not matching

In [4]: ts.unit
Out[4]: 'ns'

In [5]: ts2.unit
Out[5]: 'us'

However, I suppose the unit should probably reflect changes when .replace is used.

@mroeschke mroeschke changed the title BUG: Comparison of timestamp with same value failed BUG: Timestamp.unit should reflect changes in components after Timestamp.replace Mar 6, 2024
@mroeschke mroeschke added Non-Nano datetime64/timedelta64 with non-nanosecond resolution and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 6, 2024
@diogomsmiranda
Copy link

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Non-Nano datetime64/timedelta64 with non-nanosecond resolution
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants