Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace usages of copy_arrays with memmap for asdf>=3.1.0 #230

Merged
merged 5 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- drop support for python 3.9. [#232]

- replace usages of ``copy_arrays`` with ``memmap`` [#230]

0.6.1 (2024-04-05)
------------------
Expand Down
19 changes: 13 additions & 6 deletions asdf_astropy/converters/unit/tests/test_quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@
from asdf.testing import helpers
from astropy import units
from astropy.units import Quantity
from astropy.utils.introspection import minversion
from numpy.testing import assert_array_equal


def asdf_open_memory_mapping_kwarg(memmap: bool) -> dict:
braingram marked this conversation as resolved.
Show resolved Hide resolved
zacharyburnett marked this conversation as resolved.
Show resolved Hide resolved
if minversion("asdf", "3.1.0"):
return {"memmap": memmap}
return {"copy_arrays": not memmap}

Check warning on line 14 in asdf_astropy/converters/unit/tests/test_quantity.py

View check run for this annotation

Codecov / codecov/patch

asdf_astropy/converters/unit/tests/test_quantity.py#L14

Added line #L14 was not covered by tests


def create_quantities():
return [
# Scalar:
Expand Down Expand Up @@ -77,7 +84,7 @@

def test_memmap(tmp_path):
"""
Test that memmap (copy_arrays=False) works with quantities.
Test that memmap (memmap=True) works with quantities.

Unfortunately, this is not a simple `isinstance(obj, np.memmap)`
Instead it requires a more complicated check.
Expand All @@ -95,7 +102,7 @@
af.write_to(file_path)

# Update a value in the ASDF file
with asdf.open(file_path, mode="rw", copy_arrays=False) as af:
with asdf.open(file_path, mode="rw", **asdf_open_memory_mapping_kwarg(memmap=True)) as af:
assert (af.tree["quantity"] == quantity).all()
assert af.tree["quantity"][-1, -1] != new_value

Expand All @@ -105,15 +112,15 @@
assert (af.tree["quantity"] != quantity).any()
assert (af.tree["quantity"] == new_quantity).all()

with asdf.open(file_path, mode="rw", copy_arrays=False) as af:
with asdf.open(file_path, mode="rw", **asdf_open_memory_mapping_kwarg(memmap=True)) as af:
assert af.tree["quantity"][-1, -1] == new_value
assert (af.tree["quantity"] != quantity).any()
assert (af.tree["quantity"] == new_quantity).all()


def test_no_memmap(tmp_path):
"""
Test that turning off memmap (copy_arrays=True) works as expected for quantities
Test that turning off memmap (memmap=False) works as expected for quantities
"""
file_path = tmp_path / "test.asdf"
quantity = Quantity(np.arange(100, dtype=np.float64).reshape(5, 20), units.km)
Expand All @@ -128,7 +135,7 @@
af.write_to(file_path)

# Update a value in the ASDF file
with asdf.open(file_path, mode="rw", copy_arrays=True) as af:
with asdf.open(file_path, mode="rw", **asdf_open_memory_mapping_kwarg(memmap=False)) as af:
assert (af.tree["quantity"] == quantity).all()
assert af.tree["quantity"][-1, -1] != new_value

Expand All @@ -138,7 +145,7 @@
assert (af.tree["quantity"] != quantity).any()
assert (af.tree["quantity"] == new_quantity).all()

with asdf.open(file_path, mode="rw", copy_arrays=True) as af:
with asdf.open(file_path, mode="rw", **asdf_open_memory_mapping_kwarg(memmap=False)) as af:
assert af.tree["quantity"][-1, -1] != new_value
assert (af.tree["quantity"] != new_quantity).any()
assert (af.tree["quantity"] == quantity).all()
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ extend-ignore = [
"FIX", # flake8-fixme
# Individually ignored checks
"SLF001", # private-member-access
"FBT001", # boolean positional arguments in function definition
]
extend-exclude = ["docs/*"]

Expand Down
Loading