-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
when requested (and supported) memory map external blocks by returning a numpy.memmap instance of the bytes for the block in the external file fixes #1525
- Loading branch information
Showing
4 changed files
with
51 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import numpy as np | ||
|
||
import asdf | ||
|
||
|
||
def test_1525(tmp_path): | ||
""" | ||
External blocks are always lazy loaded and memmapped | ||
https://github.com/asdf-format/asdf/issues/1525 | ||
""" | ||
|
||
fn = tmp_path / "test.asdf" | ||
arr = np.arange(10) | ||
af = asdf.AsdfFile({"arr": arr}) | ||
af.set_array_storage(arr, "external") | ||
af.write_to(fn) | ||
|
||
for copy_arrays in (True, False): | ||
with asdf.open(fn, copy_arrays=copy_arrays) as af: | ||
# check that block is external | ||
source = af["arr"]._source | ||
assert isinstance(source, str) | ||
|
||
# check if block is memmapped | ||
if copy_arrays: | ||
assert not isinstance(af["arr"].base, np.memmap) | ||
else: | ||
assert isinstance(af["arr"].base, np.memmap) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters