-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: datetime column changed after storing to hdf5 #57085
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
Comments
Hey @xbanke, I've tried it in Jupyter and Colab but it is working correctly. Colab :Jupyter : |
@PritamSarbajna, So what is the possible problem of my environment? |
There exists some difference: import numpy as np
import pandas as pd
np.random.seed(42)
df = pd.DataFrame(np.random.randn(5, 3), columns=list('abc')).assign(dt=pd.Timestamp('20240101'))
df1 = df.astype({'dt': 'datetime64[ns]'})
print(df['dt'].values)
print(df1['dt'].values)
# array(['2024-01-01T00:00:00', '2024-01-01T00:00:00',
# '2024-01-01T00:00:00', '2024-01-01T00:00:00',
# '2024-01-01T00:00:00'], dtype='datetime64[s]')
# array(['2024-01-01T00:00:00.000000000', '2024-01-01T00:00:00.000000000',
# '2024-01-01T00:00:00.000000000', '2024-01-01T00:00:00.000000000',
# '2024-01-01T00:00:00.000000000'], dtype='datetime64[ns]') |
Thanks for the report; given that non-nano resolutions are relatively new, I'm guessing that it's not yet built into hdf. Further investigations welcome! |
5 tasks
Closed by #59018 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Issue Description
Creating a dataframe with a datetime column by assigning a single
pd.Timestamp
, then storing it withto_hdf
. the datetime column changed after reading from the hdf5 file.But, if
astype
manually before storing, everthing will be OK.Expected Behavior
df
should equal todf1
Installed Versions
INSTALLED VERSIONS
commit : fd3f571
python : 3.11.4.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.0-78-generic
Version : #85-Ubuntu SMP Fri Jul 7 15:25:09 UTC 2023
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.2.0
numpy : 1.24.3
pytz : 2023.3
dateutil : 2.8.2
setuptools : 66.0.0
pip : 23.0.1
Cython : 3.0.0b2
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.1.0
lxml.etree : 4.9.2
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.16.1
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.2
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2023.9.0
gcsfs : None
matplotlib : 3.7.1
numba : 0.57.0
numexpr : 2.8.4
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : 12.0.0
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.10.1
sqlalchemy : 2.0.21
tables : 3.8.0
tabulate : None
xarray : None
xlrd : 2.0.1
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: