diff --git a/changelog/fragments/1662.fixed.rst b/changelog/fragments/1662.fixed.rst new file mode 100644 index 0000000000000000000000000000000000000000..972f51a39c2965440f4443756e1f87d24e53948c --- /dev/null +++ b/changelog/fragments/1662.fixed.rst @@ -0,0 +1 @@ +The ``compare_dict_of_arrays`` function now works witth arrays of string with multiple components. diff --git a/src/gemseo/utils/comparisons.py b/src/gemseo/utils/comparisons.py index d2a8f90e2c5484be6f4fadda9b12939af9c92550..578cdac8f7eaff280bb6c9c12a3ff43ebb11ac17 100644 --- a/src/gemseo/utils/comparisons.py +++ b/src/gemseo/utils/comparisons.py @@ -111,7 +111,7 @@ def compare_dict_of_arrays( other_array = other_array.data.reshape(-1) if array_.dtype.type is str_: - if array_ != other_array: + if (array_ != other_array).any(): return False elif not compare_arrays(array_, other_array): return False diff --git a/tests/utils/test_comparisons.py b/tests/utils/test_comparisons.py index 00993759aa0e19c04301fd0fedb1fcee8c759e5d..6796359f39001f83b59fb92b2f9ca3235907bb13 100644 --- a/tests/utils/test_comparisons.py +++ b/tests/utils/test_comparisons.py @@ -118,6 +118,8 @@ def test_array_are_close( ("string", "bad", False), (array(["string"]), array(["string"]), True), (array(["string"]), array(["bad"]), False), + (array(["string", "other_string"]), array(["string", "other_string"]), True), + (array(["string", "other_string"]), array(["string", "bad"]), False), ("string", array(["string"]), False), ], )