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 #46

Merged
merged 3 commits into from
Jul 18, 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
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
0.1.0 (unreleased)
------------------

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

0.0.4 (2024-06-28)
------------------
Expand Down
14 changes: 7 additions & 7 deletions asdf_zarr/tests/test_zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ def create_zarray(shape=None, chunks=None, dtype="f8", store=None, chunk_store=N
return arr


@pytest.mark.parametrize("copy_arrays", [True, False])
@pytest.mark.parametrize("memmap", [True, False])
@pytest.mark.parametrize("lazy_load", [True, False])
@pytest.mark.parametrize("compression", ["input", "zlib"])
@pytest.mark.parametrize("store_type", [DirectoryStore, KVStore, MemoryStore, NestedDirectoryStore, TempStore])
@pytest.mark.parametrize("to_internal", [True, False])
@pytest.mark.parametrize("meta_store", [True, False])
def test_write_to(tmp_path, copy_arrays, lazy_load, compression, store_type, to_internal, meta_store):
def test_write_to(tmp_path, memmap, lazy_load, compression, store_type, to_internal, meta_store):
if store_type in (DirectoryStore, NestedDirectoryStore):
store1 = store_type(tmp_path / "zarr_array_1")
store2 = store_type(tmp_path / "zarr_array_2")
Expand Down Expand Up @@ -66,7 +66,7 @@ def test_write_to(tmp_path, copy_arrays, lazy_load, compression, store_type, to_
af = asdf.AsdfFile(tree)
af.write_to(fn, all_array_compression=compression)

with asdf.open(fn, mode="r", copy_arrays=copy_arrays, lazy_load=lazy_load) as af:
with asdf.open(fn, mode="r", memmap=memmap, lazy_load=lazy_load) as af:
for n, a in (("arr1", arr1), ("arr2", arr2)):
assert isinstance(af[n], zarr.core.Array)
if to_internal or store_type in (KVStore, MemoryStore, TempStore):
Expand All @@ -76,10 +76,10 @@ def test_write_to(tmp_path, copy_arrays, lazy_load, compression, store_type, to_
assert numpy.allclose(af[n], a)


@pytest.mark.parametrize("copy_arrays", [True, False])
@pytest.mark.parametrize("memmap", [True, False])
@pytest.mark.parametrize("lazy_load", [True, False])
@pytest.mark.parametrize("with_update", [True, False])
def test_modify(tmp_path, with_update, copy_arrays, lazy_load):
def test_modify(tmp_path, with_update, memmap, lazy_load):
# make a file
store = DirectoryStore(tmp_path / "zarr_array")
arr = create_zarray(store=store)
Expand All @@ -89,7 +89,7 @@ def test_modify(tmp_path, with_update, copy_arrays, lazy_load):
af.write_to(fn)

# open the file, modify the array
with asdf.open(fn, mode="rw", copy_arrays=copy_arrays, lazy_load=lazy_load) as af:
with asdf.open(fn, mode="rw", memmap=memmap, lazy_load=lazy_load) as af:
assert af["arr"][0, 0] != 42
af["arr"][0, 0] = 42
# now modify
Expand All @@ -100,7 +100,7 @@ def test_modify(tmp_path, with_update, copy_arrays, lazy_load):
af.update()

# reopen the file, check for the modification
with asdf.open(fn, mode="rw", copy_arrays=copy_arrays, lazy_load=lazy_load) as af:
with asdf.open(fn, mode="rw", memmap=memmap, lazy_load=lazy_load) as af:
assert af["arr"][0, 0] == 42


Expand Down
12 changes: 6 additions & 6 deletions notebooks/ASDF_array_storage_intro.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@
"\n",
"For local files, asdf will memory map arrays allowing the operating system to read only the portion of the array that is requested.\n",
"\n",
"Note that array memory mapping can be disabled by setting the keyword argument `copy_arrays` to `True` in `asdf.open`."
"Note that array memory mapping can be disabled by setting the keyword argument `memmap` to `False` in `asdf.open`."
]
},
{
Expand All @@ -641,15 +641,15 @@
"name": "stdout",
"output_type": "stream",
"text": [
"With default copy_arrays=False\n",
"With default memmap=True\n",
"\tarray 0 base array type = <class 'numpy.memmap'>\n"
]
}
],
"source": [
"# open our example file with memory mapping (enabled by default)\n",
"with asdf.open(example_fn) as af:\n",
" print(\"With default copy_arrays=False\") \n",
" print(\"With default memmap=True\") \n",
" # the array data has a base array that is of type numpy.memmap\n",
" print(f\"\\tarray 0 base array type = {type(af['array0'].base)}\")"
]
Expand All @@ -669,15 +669,15 @@
"name": "stdout",
"output_type": "stream",
"text": [
"With copy_arrays=True\n",
"With memmap=False\n",
"\tarray 0 base array type = <class 'numpy.ndarray'>\n"
]
}
],
"source": [
"# open our example file with memory mapping disabled\n",
"with asdf.open(example_fn, copy_arrays=True) as af:\n",
" print(\"With copy_arrays=True\")\n",
"with asdf.open(example_fn, memmap=False) as af:\n",
" print(\"With memmap=False\")\n",
" print(f\"\\tarray 0 base array type = {type(af['array0'].base)}\")"
]
},
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dynamic = [
'version',
]
dependencies = [
"asdf >= 3.0.0",
"asdf >= 3.1.0",
"zarr >= 2.14, < 3.0.0",
"fsspec",
]
Expand Down