Skip to content

Commit

Permalink
Fixed a v3 compatibility bug where the attributes were not retrieved …
Browse files Browse the repository at this point in the history
…from the proper place in the HDF5-file.

Modified the generate_test_hickle.py file to now create hickled files that caused this issue before.
  • Loading branch information
1313e committed Dec 17, 2020
1 parent 869b0db commit c4b2ae6
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion hickle/__version__.py
Expand Up @@ -10,4 +10,4 @@

# %% VERSIONS
# Default/Latest/Current version
__version__ = '4.0.2'
__version__ = '4.0.3'
8 changes: 4 additions & 4 deletions hickle/hickle.py
Expand Up @@ -508,23 +508,23 @@ def load(file_obj, path='/', safe=True):
# Try to read the provided file_obj as a hickle file
try:
h5f, path, close_flag = file_opener(file_obj, path, 'r')
h_root_group = h5f.get(path)
h_root_group = h5f.get(path) # Solely used by v4

# Define attributes h_root_group must have
v3_attrs = ['CLASS', 'VERSION', 'PYTHON_VERSION']
v4_attrs = ['HICKLE_VERSION', 'HICKLE_PYTHON_VERSION']

# Check if the proper attributes for v3 loading are available
if all(map(h_root_group.attrs.get, v3_attrs)):
if all(map(h5f.attrs.get, v3_attrs)):
# Check if group attribute 'CLASS' has value 'hickle
if(h_root_group.attrs['CLASS'] != b'hickle'): # pragma: no cover
if(h5f.attrs['CLASS'] != b'hickle'): # pragma: no cover
# If not, raise error
raise AttributeError("HDF5-file attribute 'CLASS' does not "
"have value 'hickle'!")

# Obtain version with which the file was made
try:
major_version = int(h_root_group.attrs['VERSION'][0])
major_version = int(h5f.attrs['VERSION'][0])

# If this cannot be done, then this is not a v3 file
except Exception: # pragma: no cover
Expand Down
2 changes: 1 addition & 1 deletion hickle/tests/legacy_hkls/generate_test_hickle.py
Expand Up @@ -23,5 +23,5 @@
}

print("Dumping %s..." % fn_out)
hkl.dump(dd, fn_out)
hkl.dump(dd, fn_out, path='test')

Binary file not shown.
2 changes: 1 addition & 1 deletion hickle/tests/test_legacy_load.py
Expand Up @@ -22,7 +22,7 @@ def test_legacy_load():
for filename in filelist:
try:
print(filename)
a = hkl.load(filename)
a = hkl.load(filename, path='test')
except Exception:
with h5py.File(filename) as a:
print(a.attrs.items())
Expand Down

0 comments on commit c4b2ae6

Please sign in to comment.