diff --git a/CHANGES.rst b/CHANGES.rst index f459e140..e038477c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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) ------------------ diff --git a/asdf_astropy/converters/unit/tests/test_quantity.py b/asdf_astropy/converters/unit/tests/test_quantity.py index 2595131c..71c07ae2 100644 --- a/asdf_astropy/converters/unit/tests/test_quantity.py +++ b/asdf_astropy/converters/unit/tests/test_quantity.py @@ -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: + if minversion("asdf", "3.1.0"): + return {"memmap": memmap} + return {"copy_arrays": not memmap} + + def create_quantities(): return [ # Scalar: @@ -77,7 +84,7 @@ def test_read_array_value(): 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. @@ -95,7 +102,7 @@ def test_memmap(tmp_path): 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 @@ -105,7 +112,7 @@ def test_memmap(tmp_path): 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() @@ -113,7 +120,7 @@ def test_memmap(tmp_path): 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) @@ -128,7 +135,7 @@ def test_no_memmap(tmp_path): 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 @@ -138,7 +145,7 @@ def test_no_memmap(tmp_path): 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() diff --git a/pyproject.toml b/pyproject.toml index 9a83b079..6f5461ba 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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/*"]