-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When hashing `dtype=object` arrays we need to include the length of the individual strings, otherwise arrays with identical contents after concatenating all elements hash to the same value: ``` >>> import h5py ... import versioned_hdf5 ... import numpy as np ... ... path = "temp.h5" ... ... with h5py.File(path, mode="w") as f: ... file = versioned_hdf5.VersionedHDF5File(f) ... with file.stage_version("r0") as group: ... group.create_dataset( ... "values", shape=(2,), dtype=h5py.string_dtype(encoding='ascii'), data=np.array([b"a", b"bc"], dtype=object), ... maxshape=(None,), chunks=(10000,), compression="gzip", shuffle=False, ... ) ... with file.stage_version("r1") as group: ... group.create_dataset( ... "values", shape=(2,), dtype=h5py.string_dtype(encoding='ascii'), data=np.array([b"ab", b"c"], dtype=object), ... maxshape=(None,), chunks=(10000,), compression="gzip", shuffle=False, ... ) ... ... with h5py.File(path, mode="r") as f: ... file = versioned_hdf5.VersionedHDF5File(f) ... for i in range(2): ... print(file[f"r{i}"]["values"][:]) ... [b'a' b'bc'] [b'a' b'bc'] ``` By including the length of each string as part of the hash the hashes will now be unique. This also includes the changes in #287 and supersedes that PR. Fixes #288
- Loading branch information
Showing
5 changed files
with
69 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters