Skip to content

Commit

Permalink
Switch to logging an info message for data version mismatch; fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
peytondmurray committed Aug 8, 2023
1 parent 73dd762 commit 9b98011
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
3 changes: 1 addition & 2 deletions versioned_hdf5/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
change.
"""
import logging
import warnings
import numpy as np
from typing import Set, Optional

Expand Down Expand Up @@ -71,7 +70,7 @@ def __init__(self, f):
else:
# This is not a new file; check data version identifier for compatibility
if self.data_version_identifier != DATA_VERSION:
warnings.warn(
logger.info(
f'{f.filename} was created by a different version of '
f'versioned-hdf5. Object dtypes may not be accessed correctly. '
f'File has data version identifier {self.data_version_identifier}, '
Expand Down
1 change: 1 addition & 0 deletions versioned_hdf5/hashtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def hash(self, data):
hash_value = self.hash_function()
for value in data.flat:
hash_value.update(bytes(str(value), 'utf-8'))
hash_value.update(bytes(str(data.shape), 'utf-8'))
return hash_value.digest()
else:
return self.hash_function(
Expand Down
12 changes: 7 additions & 5 deletions versioned_hdf5/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1896,8 +1896,9 @@ def test_data_version_identifier_valid(tmp_path):
VersionedHDF5File(f)


def test_data_version_identifier_missing(tmp_path):
"""Test that a file with no data version identifier raises a warning when opened."""
def test_data_version_identifier_missing(tmp_path, caplog):
"""Test that a file with no data version identifier logs a message when opened."""
caplog.set_level(logging.INFO)
filename = pathlib.Path(tmp_path) / 'file.h5'
with h5py.File(filename, 'w') as f:
VersionedHDF5File(f)
Expand All @@ -1906,6 +1907,7 @@ def test_data_version_identifier_missing(tmp_path):
# equivalent to v1.
del f['_version_data/versions'].attrs['data_version']

with warns(UserWarning):
with h5py.File(filename, 'r') as f:
VersionedHDF5File(f)
with h5py.File(filename, 'r') as f:
VersionedHDF5File(f)

assert len(caplog.records) == 1

0 comments on commit 9b98011

Please sign in to comment.