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

raise AttributeError for __asdf_traverse__ on NDArrayType #1572

Merged
merged 3 commits into from
Aug 7, 2023
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 @@ -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