Skip to content

Commit

Permalink
Merge pull request #1572 from braingram/info_array_loading
Browse files Browse the repository at this point in the history
raise AttributeError for __asdf_traverse__ on NDArrayType
  • Loading branch information
braingram authored Aug 7, 2023
2 parents ed46538 + 3c36138 commit bf1843e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The ASDF Standard is at v1.6.0
- Remove deprecated TagDefinition.schema_uri [#1595]
- Removed deprecated AsdfFile.open and deprecated asdf.open
AsdfFile.write_to and AsdfFile.update kwargs [#1592]
- Fix ``AsdfFile.info`` loading all array data [#1572]

2.15.1 (2023-08-07)
-------------------
Expand Down
19 changes: 19 additions & 0 deletions asdf/_tests/_regtests/test_1553.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import numpy as np

import asdf


def test_asdf_info_should_not_load_arrays(tmp_path):
"""
AsdfFile.info should not load array data
https://github.com/asdf-format/asdf/issues/1553
"""
fn = tmp_path / "test.asdf"
tree = dict([(k, np.arange(ord(k))) for k in "abc"])
asdf.AsdfFile(tree).write_to(fn)

with asdf.open(fn) as af:
assert "unloaded" in str(af["b"])
af.info()
assert "unloaded" in str(af["b"])
7 changes: 7 additions & 0 deletions asdf/tags/core/ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,13 @@ def __getattr__(self, attr):
# number of array creations in the general case.
if attr == "__array_struct__":
raise AttributeError
# AsdfFile.info will call hasattr(obj, "__asdf_traverse__") which
# will trigger this method, making the array, and loading the array
# data. Intercept this and raise AttributeError as this class does
# not support that method
# see: https://github.com/asdf-format/asdf/issues/1553
if attr == "__asdf_traverse__":
raise AttributeError
return getattr(self._make_array(), attr)

def __setitem__(self, *args):
Expand Down

0 comments on commit bf1843e

Please sign in to comment.