Skip to content

DOC/DEPR: to_hdf produces a different file each time #51456

Open
@cschell

Description

@cschell

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

# %% setup
import numpy as np
import hashlib

test_data = np.arange(9).reshape(3,3)

# %% hash of pandas/pytables output changes every time


import pandas as pd
pd.DataFrame(test_data).to_hdf("file_a.h5", key="test")
print("pandas hash", hashlib.md5(open("file_a.h5", "rb").read()).hexdigest())


# %% h5py hash stays the same
import h5py

with h5py.File("file_b.h5", "w") as f:
    dset = f.create_dataset("demo", (3,3), dtype='f')
    dset[...] = test_data

print("h5py hash", hashlib.md5(open("file_b.h5", "rb").read()).hexdigest())

Issue Description

Currently, to_hdf produces a different file, even though the data itself does not change. Perhaps there are timestamps or similar added on a lower level, which ultimately produces different hashes for practically the same contents.

Expected Behavior

I would expect to_hdf to be deterministic, so it should write the same bits to the disk if the input stays the same. In my case this would help versioning hdf5 files produced with pandas, since I can use the md5/sha/whatever hash to reference a specific version, and verify that my pipeline is producing the same (or different) data files.
As a comparison, h5py produces the same file each time.

Installed Versions

INSTALLED VERSIONS

commit : 8dab54d
python : 3.10.6.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.0-52-generic
Version : #58-Ubuntu SMP Thu Oct 13 08:03:55 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : en_GB.UTF-8
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8

pandas : 1.5.2
numpy : 1.23.5
pytz : 2022.6
dateutil : 2.8.2
setuptools : 65.6.3
pip : 23.0
Cython : 0.29.32
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.0.3
lxml.etree : 4.9.1
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.8.0
pandas_datareader: None
bs4 : 4.8.2
bottleneck : None
brotli : None
fastparquet : None
fsspec : 2022.11.0
gcsfs : None
matplotlib : 3.6.2
numba : None
numexpr : 2.8.4
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.10.0
snappy : None
sqlalchemy : None
tables : 3.8.0
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : None
zstandard : None
tzdata : 2022.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeprecateFunctionality to remove in pandasDocsIO HDF5read_hdf, HDFStore

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions