Skip to content

Commit

Permalink
Allow loading npz files which use DEFLATE compression
Browse files Browse the repository at this point in the history
This does not change file saving, we are still only using STORED
in this case
  • Loading branch information
Luthaf committed Jul 3, 2024
1 parent 2783dd8 commit 4f222bb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion metatensor-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ smallvec = {version = "1", features = ["union"]}
# implementation of the NPZ serialization format
byteorder = {version = "1"}
num-traits = {version = "0.2", default-features = false}
zip = {version = "0.6", default-features = false}
zip = {version = "0.6", default-features = false, features = ["deflate"]}

[build-dependencies]
cbindgen = { version = "0.26", default-features = false }
Expand Down
24 changes: 24 additions & 0 deletions python/metatensor-core/tests/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,30 @@ def test_load(use_numpy, memory_buffer, standalone_fn):
assert gradient.values.shape == (59, 3, 5, 3)


@pytest.mark.parametrize("use_numpy", (True, False))
def test_load_deflate(use_numpy):
# This file was saved using DEFLATE to compress the different ZIP archive members
path = os.path.join(
os.path.dirname(__file__),
"..",
"..",
"metatensor-operations",
"tests",
"data",
"qm7-power-spectrum.npz",
)

tensor = metatensor.load(path, use_numpy=use_numpy)

assert isinstance(tensor, TensorMap)
assert tensor.keys.names == [
"center_type",
"neighbor_1_type",
"neighbor_2_type",
]
assert len(tensor.keys) == 17


# using tmpdir as pytest-built-in fixture
# https://docs.pytest.org/en/7.1.x/how-to/tmp_path.html#the-tmpdir-and-tmpdir-factory-fixtures
@pytest.mark.parametrize("use_numpy", (True, False))
Expand Down

0 comments on commit 4f222bb

Please sign in to comment.