Skip to content

Commit

Permalink
don't compress array snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
wpbonelli committed May 13, 2024
1 parent 304ed9e commit 0ac5d48
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 39 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,6 @@ jobs:
working-directory: modflow6-examples/autotest
run: pytest -v -n auto test_scripts.py --init

- name: Debug with tmate
if: matrix.os == 'ubuntu-22.04'
uses: mxschmitt/action-tmate@v3

- name: Run local tests
working-directory: modflow-devtools/autotest
env:
Expand Down
Binary file not shown.
Binary file not shown.
6 changes: 3 additions & 3 deletions autotest/test_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,13 @@ def test_binary_array_snapshot(array_snapshot):
assert np.allclose(np.load(snapshot_path), snapshot_array)


def test_multi_array_snapshot(multi_array_snapshot):
def test_binary_array_snapshot_multi(array_snapshot):
arrays = {"ascending": snapshot_array, "descending": np.flip(snapshot_array)}
assert multi_array_snapshot == arrays
assert array_snapshot == arrays
snapshot_path = (
snapshots_path
/ module_path.stem
/ f"{inspect.currentframe().f_code.co_name}.npz"
/ f"{inspect.currentframe().f_code.co_name}.npy"
)
assert snapshot_path.is_file()
assert np.allclose(np.load(snapshot_path)["ascending"], snapshot_array)
Expand Down
37 changes: 5 additions & 32 deletions modflow_devtools/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ def _serialize_bytes(data):
if isinstance(data, dict):
# sort by keys
data = OrderedDict(sorted(data.items()))
np.savez_compressed(buffer, **data)
np.savez(buffer, **data)
else:
np.save(buffer, data)
return buffer.getvalue()


class BinaryArrayExtension(SingleFileSnapshotExtension):
"""
Binary snapshot of a NumPy array. Can be read back into NumPy with
.load(), preserving dtype and shape. This is the recommended array
snapshot approach if human-readability is not a necessity, as disk
space is minimized.
Binary snapshot of one or more NumPy arrays. Can be read back into
NumPy with .load(), preserving dtype and shape. Note, .load() will
return a dict mapping array names to arrays if such a dict was the
snapshot value, otherwise .load() just returns the snapshot array.
"""

_write_mode = WriteMode.BINARY
Expand All @@ -61,28 +61,6 @@ def serialize(
return _serialize_bytes(data)


class CompressedArrayExtension(SingleFileSnapshotExtension):
"""
Compressed snapshot of one or more NumPy arrays. Can be read back into
NumPy with .load(), preserving dtype and shape. Note that .load() will
return a dict mapping array names to arrays. Use this extension rather
than BinaryArrayExtension for tests requiring multiple array snapshots.
"""

_write_mode = WriteMode.BINARY
_file_extension = "npz"

def serialize(
self,
data,
*,
exclude=None,
include=None,
matcher=None,
):
return _serialize_bytes(data)


class TextArrayExtension(SingleFileSnapshotExtension):
"""
Text snapshot of a NumPy array. Flattens the array before writing.
Expand Down Expand Up @@ -212,11 +190,6 @@ def array_snapshot(snapshot):
return snapshot.use_extension(BinaryArrayExtension)


@pytest.fixture
def multi_array_snapshot(snapshot):
return snapshot.use_extension(CompressedArrayExtension)


@pytest.fixture
def text_array_snapshot(snapshot):
return snapshot.use_extension(TextArrayExtension)
Expand Down

0 comments on commit 0ac5d48

Please sign in to comment.