diff --git a/CHANGES.rst b/CHANGES.rst index ebe858921..12293df83 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -25,6 +25,10 @@ The ASDF Standard is at v1.6.0 ``asdf.tags.core.Stream``, update block storage support for Converter and update internal block API [#1537] - Remove deprecated resolve_local_refs argument to load_schema [#1623] +- Move IntegerType to converter and drop cache of converted values. [#1527] +- Remove legacy extension API [#1637] +- Fix bug that left out the name of the arrays that differed + for ``asdftool diff`` comparisons [#1652] 2.15.2 (2023-09-29) ------------------- @@ -33,8 +37,6 @@ The ASDF Standard is at v1.6.0 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - Add support for python 3.12 [#1641] -- Move IntegerType to converter and drop cache of converted values. [#1527] -- Remove legacy extension API [#1637] 2.15.1 (2023-08-07) ------------------- diff --git a/asdf/_tests/commands/tests/data/blocks.diff b/asdf/_tests/commands/tests/data/blocks.diff index 55978d20f..9f04a8167 100644 --- a/asdf/_tests/commands/tests/data/blocks.diff +++ b/asdf/_tests/commands/tests/data/blocks.diff @@ -10,4 +10,4 @@ tree: - > 9000 < 10000 - ndarrays differ by shape, datatype and contents + ndarrays at "foobar" differ by shape, datatype and contents diff --git a/asdf/_tests/commands/tests/data/ndarray0.asdf b/asdf/_tests/commands/tests/data/ndarray0.asdf new file mode 100644 index 000000000..728527515 Binary files /dev/null and b/asdf/_tests/commands/tests/data/ndarray0.asdf differ diff --git a/asdf/_tests/commands/tests/data/ndarray1.asdf b/asdf/_tests/commands/tests/data/ndarray1.asdf new file mode 100644 index 000000000..8074106c7 Binary files /dev/null and b/asdf/_tests/commands/tests/data/ndarray1.asdf differ diff --git a/asdf/_tests/commands/tests/data/ndarrays.diff b/asdf/_tests/commands/tests/data/ndarrays.diff new file mode 100644 index 000000000..5e400cacb --- /dev/null +++ b/asdf/_tests/commands/tests/data/ndarrays.diff @@ -0,0 +1 @@ + ndarrays at "a" differ by contents diff --git a/asdf/_tests/commands/tests/data/simple_inline_array.diff b/asdf/_tests/commands/tests/data/simple_inline_array.diff index ba2b7a18e..3e30e30c1 100644 --- a/asdf/_tests/commands/tests/data/simple_inline_array.diff +++ b/asdf/_tests/commands/tests/data/simple_inline_array.diff @@ -1 +1 @@ - ndarrays differ by contents + ndarrays at "array" differ by contents diff --git a/asdf/_tests/commands/tests/test_diff.py b/asdf/_tests/commands/tests/test_diff.py index 45c93d8eb..d96eb6849 100644 --- a/asdf/_tests/commands/tests/test_diff.py +++ b/asdf/_tests/commands/tests/test_diff.py @@ -48,6 +48,12 @@ def test_diff_ignore(result_file, ignore): _assert_diffs_equal(filenames, result_file, minimal=False, ignore=ignore) +def test_diff_ndarray(): + filenames = ["ndarray0.asdf", "ndarray1.asdf"] + result_file = "ndarrays.diff" + _assert_diffs_equal(filenames, result_file, minimal=False) + + def test_diff_block(): filenames = ["block0.asdf", "block1.asdf"] result_file = "blocks.diff" diff --git a/asdf/commands/diff.py b/asdf/commands/diff.py index d1e2f70c1..fa8776ad7 100644 --- a/asdf/commands/diff.py +++ b/asdf/commands/diff.py @@ -6,6 +6,7 @@ import sys import jmespath +import numpy as np from numpy import array_equal try: @@ -30,6 +31,7 @@ RESET = "" import asdf +from asdf.extension._serialization_context import BlockAccess from asdf.tagged import Tagged from asdf.util import human_list @@ -243,6 +245,16 @@ def print_dict_diff(diff_ctx, tree, node_list, keys, other): print_in_tree(diff_ctx, nodes, key_, other, use_marker=use_marker) +def _load_array(asdf_file, array_dict): + # the array_dict may not be tagged if the array is inline + # in this case just use what's in "data" + if not hasattr(array_dict, "_tag"): + return array_dict["data"] + conv = asdf_file.extension_manager.get_converter_for_type(np.ndarray) + sctx = asdf_file._create_serialization_context(BlockAccess.READ) + return conv.from_yaml_tree(array_dict, array_dict._tag, sctx) + + def compare_ndarrays(diff_ctx, array0, array1, keys): """Compares two ndarray objects""" if isinstance(array0, list): @@ -258,19 +270,15 @@ def compare_ndarrays(diff_ctx, array0, array1, keys): if array0.get(field) != array1.get(field): differences.append(field) - def get_flat(af, keys): - for k in keys: - af = af[k] - return af + value0 = _load_array(diff_ctx.asdf0, array0) + value1 = _load_array(diff_ctx.asdf1, array1) - array0 = get_flat(diff_ctx.asdf0, keys) - array1 = get_flat(diff_ctx.asdf1, keys) - if not array_equal(array0, array1): + if not array_equal(value0, value1): differences.append("contents") if differences: prefix = " " * (len(keys) + 1) - msg = f"ndarrays differ by {human_list(differences)}" + msg = f"ndarrays at \"{'.'.join(keys)}\" differ by {human_list(differences)}" diff_ctx.iostream.write(prefix + RED + msg + RESET_NEWLINE)