Skip to content

Commit

Permalink
Merge pull request #1687 from braingram/time_info
Browse files Browse the repository at this point in the history
Display value for all childless nodes during `info`
  • Loading branch information
braingram authored Jan 15, 2024
2 parents 334f6c3 + bc16fca commit d9d9974
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 14 deletions.
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"


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

0 comments on commit d9d9974

Please sign in to comment.