Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] 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 : bdc79c146c2e32f2cab629be240f01658cfb6cc2 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
Comment From: mroeschke
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.
Comment From: diogomsmiranda
take