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

Display value for all childless nodes during info #1687

Merged
merged 4 commits into from
Jan 15, 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
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ The ASDF Standard is at v1.6.0
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

- Fix bug in ``asdftool diff`` for arrays within a list [#1672]
- For ``info`` and ``search`` show ``str`` representation of childless
(leaf) nodes if ``show_values`` is enabled [#1687]
- Deprecate ``asdf.util.is_primitive`` [#1687]

3.0.0 (2023-10-16)
------------------
Expand Down
6 changes: 3 additions & 3 deletions asdf/_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

from ._node_info import create_tree
from .tags.core.ndarray import NDArrayType
from .util import is_primitive

__all__ = [
"DEFAULT_MAX_ROWS",
Expand Down Expand Up @@ -252,12 +251,13 @@ def _render_node(self, info, active_depths, is_tail):

def _render_node_value(self, info):
rendered_type = type(info.node).__name__
if is_primitive(info.node) and self._show_values:
return f"({rendered_type}): {info.node}"

if isinstance(info.node, (NDArrayType, np.ndarray)):
return f"({rendered_type}): shape={info.node.shape}, dtype={info.node.dtype.name}"

if not info.children and self._show_values:
return f"({rendered_type}): {info.node}"

return f"({rendered_type})"

def _make_prefix(self, depth, active_depths, is_tail):
Expand Down
5 changes: 5 additions & 0 deletions asdf/_tests/test_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,8 @@ def test_find_references_during_open_deprecation(tmp_path):
with pytest.warns(AsdfDeprecationWarning, match="find_references during open"):
with asdf.open(fn) as af:
pass


def test_asdf_util_is_primitive_deprecation():
with pytest.warns(AsdfDeprecationWarning, match="asdf.util.is_primitive is deprecated"):
asdf.util.is_primitive(1)
3 changes: 3 additions & 0 deletions asdf/_tests/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,9 @@ def __init__(self):
def __asdf_traverse__(self):
return {"the_meaning": self.the_meaning, "clown": self.clown, "recursive": self.recursive}

def __str__(self):
return "rec ref"
Copy link
Contributor Author

@braingram braingram Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added because with this PR (and without this change) the assert in test_recursive_info_object_support:

assert "recursive reference" in captured.out

would fail. This was due to the output line being truncated due to this test object (RecursiveObjectWithInfoSupport) not having a __str__ and defaulting to the verbose <asdf._tests.test_info.RecursiveObjectWithInfoSupport object at 0x11cba1120>. This pushes the output line beyond the max_cols limit and cuts off the recursive reference string (that is appended to the end of the long line). This test failure could have also been fixed by increasing max_cols.



def test_recursive_info_object_support(capsys, tmp_path):
tempdir = pathlib.Path(tempfile.mkdtemp())
Expand Down
10 changes: 6 additions & 4 deletions asdf/_tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@


def test_is_primitive():
for value in [None, "foo", 1, 1.39, 1 + 1j, True]:
assert util.is_primitive(value) is True
with warnings.catch_warnings():
warnings.filterwarnings("ignore", "asdf.util.is_primitive is deprecated", AsdfDeprecationWarning)
for value in [None, "foo", 1, 1.39, 1 + 1j, True]:
assert util.is_primitive(value) is True

for value in [[], (), {}, set()]:
assert util.is_primitive(value) is False
for value in [[], (), {}, set()]:
assert util.is_primitive(value) is False


def test_not_set():
Expand Down
16 changes: 9 additions & 7 deletions asdf/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
from importlib_metadata import packages_distributions
from packaging.version import Version

from . import constants
from .exceptions import AsdfDeprecationWarning
from . import constants, exceptions

# We're importing our own copy of urllib.parse because
# we need to patch it to support asdf:// URIs, but it'd
Expand Down Expand Up @@ -78,7 +77,7 @@ def human_list(line, separator="and"):
>>> human_list(["vanilla", "strawberry", "chocolate"], "or") # doctest: +SKIP
'vanilla, strawberry or chocolate'
"""
warnings.warn("asdf.util.human_list is deprecated", AsdfDeprecationWarning)
warnings.warn("asdf.util.human_list is deprecated", exceptions.AsdfDeprecationWarning)
if len(line) == 1:
return line[0]

Expand Down Expand Up @@ -126,7 +125,7 @@ def iter_subclasses(cls):
"""
Returns all subclasses of a class.
"""
warnings.warn("asdf.util.iter_subclasses is deprecated", AsdfDeprecationWarning)
warnings.warn("asdf.util.iter_subclasses is deprecated", exceptions.AsdfDeprecationWarning)
yield from _iter_subclasses(cls)


Expand Down Expand Up @@ -289,7 +288,9 @@ def resolve_name(name):
If the module or named object is not found.
"""

warnings.warn("asdf.util.resolve_name is deprecated, see astropy.utils.resolve_name", AsdfDeprecationWarning)
warnings.warn(
"asdf.util.resolve_name is deprecated, see astropy.utils.resolve_name", exceptions.AsdfDeprecationWarning
)

# Note: On python 2 these must be str objects and not unicode
parts = [str(part) for part in name.split(".")]
Expand Down Expand Up @@ -366,7 +367,7 @@ def minversion(module, version, inclusive=True):
as opposed to strictly greater than (default: `True`).
"""

warnings.warn("asdf.util.minversion is deprecated, see astropy.utils.minversion", AsdfDeprecationWarning)
warnings.warn("asdf.util.minversion is deprecated, see astropy.utils.minversion", exceptions.AsdfDeprecationWarning)

if isinstance(module, types.ModuleType):
module_name = module.__name__
Expand All @@ -376,7 +377,7 @@ def minversion(module, version, inclusive=True):
module_version = None
try:
with warnings.catch_warnings():
warnings.filterwarnings("ignore", "asdf.util.resolve_name", AsdfDeprecationWarning)
warnings.filterwarnings("ignore", "asdf.util.resolve_name", exceptions.AsdfDeprecationWarning)
module = resolve_name(module_name)
except ImportError:
return False
Expand Down Expand Up @@ -468,6 +469,7 @@ def is_primitive(value):
bool
True if the value is primitive, False otherwise
"""
warnings.warn("asdf.util.is_primitive is deprecated", exceptions.AsdfDeprecationWarning)
return isinstance(value, (bool, int, float, complex, str)) or value is None


Expand Down
Loading