diff --git a/src/nomad_measurements/utils.py b/src/nomad_measurements/utils.py index 32d2ee9b..58389fca 100644 --- a/src/nomad_measurements/utils.py +++ b/src/nomad_measurements/utils.py @@ -68,9 +68,10 @@ def create_archive( def _not_equal(a, b) -> bool: - if isinstance(a, np.ndarray): - return (a != b).any() - return a != b + comparison = a != b + if isinstance(comparison, np.ndarray): + return comparison.any() + return comparison def merge_sections( # noqa: PLR0912 diff --git a/tests/test_first_utils.py b/tests/test_first_utils.py index 854f8b4b..fdf7287b 100644 --- a/tests/test_first_utils.py +++ b/tests/test_first_utils.py @@ -24,6 +24,7 @@ PureSubstanceSection, ) from nomad.metainfo import MEnum, Quantity +from nomad.units import ureg from nomad_measurements.utils import ( merge_sections, @@ -31,7 +32,8 @@ class TestComponent(Component): - float_array = Quantity(type=np.float64, shape=['*']) + float_array = Quantity(type=np.float64, shape=[2, '*']) + float_array_w_units = Quantity(type=np.float64, shape=['*'], unit='eV') bool_array = Quantity(type=bool, shape=['*']) enum_value = Quantity(type=MEnum(['A', 'B', 'C'])) @@ -39,14 +41,16 @@ class TestComponent(Component): def test_merge_sections(capfd): component_1 = TestComponent( mass_fraction=1, - float_array=[1.0, 1.0], + float_array=[[1.0, 1.0], [1.0, 3.0]], + float_array_w_units=[1.0, 1.0], bool_array=[True, False], enum_value='A', ) component_2 = TestComponent( name='Cu', mass_fraction=1, - float_array=[1.0, 3.0], + float_array=[[1.0, 3.0], [1.0, 3.0]], + float_array_w_units=[1.0, 1.0], bool_array=[True, True], enum_value='A', ) @@ -86,8 +90,10 @@ def test_merge_sections(capfd): assert system_1.components[0].name == 'Cu' assert system_1.components[0].bool_array[0] is True assert system_1.components[0].bool_array[1] is False - assert system_1.components[0].float_array[0] == 1.0 - assert system_1.components[0].float_array[1] == 1.0 + assert system_1.components[0].float_array[0][0] == 1.0 + assert system_1.components[0].float_array[0][1] == 1.0 + assert system_1.components[0].float_array_w_units[0] == ureg.Quantity(1.0, 'eV') + assert system_1.components[0].float_array_w_units[1] == ureg.Quantity(1.0, 'eV') assert system_1.components[0].enum_value == 'A' assert system_1.components[1].name == 'Cu' assert system_1.components[1].pure_substance.name == 'Cu'