From b18a6dfd17f296723e666e8ea09635596052ac89 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 11 Dec 2022 05:16:59 +0000 Subject: [PATCH 01/12] partial fix --- pint/facets/numpy/numpy_func.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pint/facets/numpy/numpy_func.py b/pint/facets/numpy/numpy_func.py index 2c07281b8..48f817e7e 100644 --- a/pint/facets/numpy/numpy_func.py +++ b/pint/facets/numpy/numpy_func.py @@ -178,6 +178,8 @@ def get_op_output_unit(unit_op, first_input_units, all_args=None, size=None): for x in all_args: if hasattr(x, "units"): product *= x.units + elif _is_sequence_with_quantity_elements(x): + product *= x[0].units result_unit = product elif unit_op == "delta": result_unit = (1 * first_input_units - 1 * first_input_units).units @@ -186,6 +188,8 @@ def get_op_output_unit(unit_op, first_input_units, all_args=None, size=None): for x in all_args[1:]: if hasattr(x, "units"): product /= x.units + elif _is_sequence_with_quantity_elements(x): + product /= x[0].units result_unit = product elif unit_op == "div": # Start with first arg in numerator, all others in denominator @@ -195,6 +199,8 @@ def get_op_output_unit(unit_op, first_input_units, all_args=None, size=None): for x in all_args[1:]: if hasattr(x, "units"): product /= x.units + elif _is_sequence_with_quantity_elements(x): + product /= x[0].units result_unit = product elif unit_op == "variance": result_unit = ((1 * first_input_units + 1 * first_input_units) ** 2).units @@ -218,6 +224,8 @@ def get_op_output_unit(unit_op, first_input_units, all_args=None, size=None): for x in all_args[1:]: if hasattr(x, "units"): product /= x.units + elif _is_sequence_with_quantity_elements(x): + product /= x[0].units result_unit = product**-1 else: raise ValueError("Output unit method {} not understood".format(unit_op)) @@ -421,6 +429,7 @@ def implementation(*args, **kwargs): "nextafter", "trunc", "absolute", + "positive", "negative", "maximum", "minimum", From c93cad54ebb4cadaa127d1a235d0766b0a1df33d Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 11 Dec 2022 05:17:29 +0000 Subject: [PATCH 02/12] cleanup functions --- pint/facets/numpy/numpy_func.py | 55 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/pint/facets/numpy/numpy_func.py b/pint/facets/numpy/numpy_func.py index 48f817e7e..7bb4902ac 100644 --- a/pint/facets/numpy/numpy_func.py +++ b/pint/facets/numpy/numpy_func.py @@ -171,37 +171,40 @@ def get_op_output_unit(unit_op, first_input_units, all_args=None, size=None): """ all_args = all_args or [] - if unit_op == "sum": - result_unit = (1 * first_input_units + 1 * first_input_units).units - elif unit_op == "mul": + def multiply_units(args): product = first_input_units._REGISTRY.parse_units("") for x in all_args: if hasattr(x, "units"): product *= x.units elif _is_sequence_with_quantity_elements(x): product *= x[0].units - result_unit = product + return product + + def get_numerator_unit(arg): + if _is_sequence_with_quantity_elements(arg): + return getattr( + arg[0], "units", first_input_units._REGISTRY.parse_units("") + ) + else: + return getattr( + arg, "units", first_input_units._REGISTRY.parse_units("") + ) + + if unit_op == "sum": + result_unit = (1 * first_input_units + 1 * first_input_units).units + elif unit_op == "mul": + result_unit = multiply_units(all_args) elif unit_op == "delta": result_unit = (1 * first_input_units - 1 * first_input_units).units elif unit_op == "delta,div": - product = (1 * first_input_units - 1 * first_input_units).units - for x in all_args[1:]: - if hasattr(x, "units"): - product /= x.units - elif _is_sequence_with_quantity_elements(x): - product /= x[0].units - result_unit = product + numerator_unit = (1 * first_input_units - 1 * first_input_units).units + denominator_unit = multiply_units(all_args[1:]) + result_unit = numerator_unit/denominator_unit elif unit_op == "div": # Start with first arg in numerator, all others in denominator - product = getattr( - all_args[0], "units", first_input_units._REGISTRY.parse_units("") - ) - for x in all_args[1:]: - if hasattr(x, "units"): - product /= x.units - elif _is_sequence_with_quantity_elements(x): - product /= x[0].units - result_unit = product + numerator_unit = get_numerator_unit(all_args[0]) + denominator_unit = multiply_units(all_args[1:]) + result_unit = numerator_unit/denominator_unit elif unit_op == "variance": result_unit = ((1 * first_input_units + 1 * first_input_units) ** 2).units elif unit_op == "square": @@ -218,15 +221,9 @@ def get_op_output_unit(unit_op, first_input_units, all_args=None, size=None): result_unit = first_input_units**size elif unit_op == "invdiv": # Start with first arg in numerator, all others in denominator - product = getattr( - all_args[0], "units", first_input_units._REGISTRY.parse_units("") - ) - for x in all_args[1:]: - if hasattr(x, "units"): - product /= x.units - elif _is_sequence_with_quantity_elements(x): - product /= x[0].units - result_unit = product**-1 + numerator_unit = get_numerator_unit(all_args[0]) + denominator_unit = multiply_units(all_args[1:]) + result_unit = (numerator_unit/denominator_unit)**-1 else: raise ValueError("Output unit method {} not understood".format(unit_op)) From 10283e4c6835b5d2c4b2739a09d8459836207131 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 11 Dec 2022 15:25:13 +0000 Subject: [PATCH 03/12] fixed --- pint/facets/numpy/numpy_func.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pint/facets/numpy/numpy_func.py b/pint/facets/numpy/numpy_func.py index 7bb4902ac..d7c163d41 100644 --- a/pint/facets/numpy/numpy_func.py +++ b/pint/facets/numpy/numpy_func.py @@ -173,7 +173,7 @@ def get_op_output_unit(unit_op, first_input_units, all_args=None, size=None): def multiply_units(args): product = first_input_units._REGISTRY.parse_units("") - for x in all_args: + for x in args: if hasattr(x, "units"): product *= x.units elif _is_sequence_with_quantity_elements(x): @@ -193,7 +193,7 @@ def get_numerator_unit(arg): if unit_op == "sum": result_unit = (1 * first_input_units + 1 * first_input_units).units elif unit_op == "mul": - result_unit = multiply_units(all_args) + result_unit = multiply_units(all_args) elif unit_op == "delta": result_unit = (1 * first_input_units - 1 * first_input_units).units elif unit_op == "delta,div": From 65e62474ff394459585da68b7ee0132903098b79 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 11 Dec 2022 15:41:53 +0000 Subject: [PATCH 04/12] tests --- pint/facets/numpy/numpy_func.py | 16 ++++++---------- pint/testsuite/test_issues.py | 9 +++++++++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/pint/facets/numpy/numpy_func.py b/pint/facets/numpy/numpy_func.py index d7c163d41..b5945a562 100644 --- a/pint/facets/numpy/numpy_func.py +++ b/pint/facets/numpy/numpy_func.py @@ -182,29 +182,25 @@ def multiply_units(args): def get_numerator_unit(arg): if _is_sequence_with_quantity_elements(arg): - return getattr( - arg[0], "units", first_input_units._REGISTRY.parse_units("") - ) + return getattr(arg[0], "units", first_input_units._REGISTRY.parse_units("")) else: - return getattr( - arg, "units", first_input_units._REGISTRY.parse_units("") - ) + return getattr(arg, "units", first_input_units._REGISTRY.parse_units("")) if unit_op == "sum": result_unit = (1 * first_input_units + 1 * first_input_units).units elif unit_op == "mul": - result_unit = multiply_units(all_args) + result_unit = multiply_units(all_args) elif unit_op == "delta": result_unit = (1 * first_input_units - 1 * first_input_units).units elif unit_op == "delta,div": numerator_unit = (1 * first_input_units - 1 * first_input_units).units denominator_unit = multiply_units(all_args[1:]) - result_unit = numerator_unit/denominator_unit + result_unit = numerator_unit / denominator_unit elif unit_op == "div": # Start with first arg in numerator, all others in denominator numerator_unit = get_numerator_unit(all_args[0]) denominator_unit = multiply_units(all_args[1:]) - result_unit = numerator_unit/denominator_unit + result_unit = numerator_unit / denominator_unit elif unit_op == "variance": result_unit = ((1 * first_input_units + 1 * first_input_units) ** 2).units elif unit_op == "square": @@ -223,7 +219,7 @@ def get_numerator_unit(arg): # Start with first arg in numerator, all others in denominator numerator_unit = get_numerator_unit(all_args[0]) denominator_unit = multiply_units(all_args[1:]) - result_unit = (numerator_unit/denominator_unit)**-1 + result_unit = (numerator_unit / denominator_unit) ** -1 else: raise ValueError("Output unit method {} not understood".format(unit_op)) diff --git a/pint/testsuite/test_issues.py b/pint/testsuite/test_issues.py index a07e850fa..3d2d144ca 100644 --- a/pint/testsuite/test_issues.py +++ b/pint/testsuite/test_issues.py @@ -862,6 +862,15 @@ def test_issue_1300(self): m = module_registry.Measurement(1, 0.1, "meter") assert m.default_format == "~P" + @helpers.requires_numpy() + def test_issue1674(self, module_registry): + Q_ = module_registry.Quantity + arr_of_q = np.array([Q_(2, "m"), Q_(4, "m")], dtype="object") + q_arr = Q_(np.array([1, 2]), "m") + + helpers.assert_quantity_almost_equal(arr_of_q * q_arr, Q_([2, 8], "m^2")) + helpers.assert_quantity_almost_equal(arr_of_q / q_arr, Q_([2, 2], "")) + if np is not None: From c06a0d0de10d6f57caf28c8fe7b1d24826ab8bbf Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 11 Dec 2022 15:44:26 +0000 Subject: [PATCH 05/12] changes --- CHANGES | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES b/CHANGES index 19a41d997..34b56a3ab 100644 --- a/CHANGES +++ b/CHANGES @@ -8,6 +8,9 @@ Pint Changelog (PR #1629) - Add new SI prefixes: ronna-, ronto-, quetta-, quecto-. (PR #1652) +- Fixed bug causing operations between arrays of quantity scalars and quantity holding + array resulting in incorrect units. + (PR #1677) 0.20.1 (2022-10-27) From 2ab9f0fea797aad6cda95afb9adc972faa9044ba Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 23 Jun 2023 19:37:02 +0100 Subject: [PATCH 06/12] new implementation --- pint/facets/numpy/numpy_func.py | 56 ++++++++++++++++++--------------- pint/testsuite/test_issues.py | 14 +++++++-- 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/pint/facets/numpy/numpy_func.py b/pint/facets/numpy/numpy_func.py index b5945a562..31c5955cb 100644 --- a/pint/facets/numpy/numpy_func.py +++ b/pint/facets/numpy/numpy_func.py @@ -171,36 +171,31 @@ def get_op_output_unit(unit_op, first_input_units, all_args=None, size=None): """ all_args = all_args or [] - def multiply_units(args): - product = first_input_units._REGISTRY.parse_units("") - for x in args: - if hasattr(x, "units"): - product *= x.units - elif _is_sequence_with_quantity_elements(x): - product *= x[0].units - return product - - def get_numerator_unit(arg): - if _is_sequence_with_quantity_elements(arg): - return getattr(arg[0], "units", first_input_units._REGISTRY.parse_units("")) - else: - return getattr(arg, "units", first_input_units._REGISTRY.parse_units("")) - if unit_op == "sum": result_unit = (1 * first_input_units + 1 * first_input_units).units elif unit_op == "mul": - result_unit = multiply_units(all_args) + product = first_input_units._REGISTRY.parse_units("") + for x in all_args: + if hasattr(x, "units"): + product *= x.units + result_unit = product elif unit_op == "delta": result_unit = (1 * first_input_units - 1 * first_input_units).units elif unit_op == "delta,div": - numerator_unit = (1 * first_input_units - 1 * first_input_units).units - denominator_unit = multiply_units(all_args[1:]) - result_unit = numerator_unit / denominator_unit + product = (1 * first_input_units - 1 * first_input_units).units + for x in all_args[1:]: + if hasattr(x, "units"): + product /= x.units + result_unit = product elif unit_op == "div": # Start with first arg in numerator, all others in denominator - numerator_unit = get_numerator_unit(all_args[0]) - denominator_unit = multiply_units(all_args[1:]) - result_unit = numerator_unit / denominator_unit + product = getattr( + all_args[0], "units", first_input_units._REGISTRY.parse_units("") + ) + for x in all_args[1:]: + if hasattr(x, "units"): + product /= x.units + result_unit = product elif unit_op == "variance": result_unit = ((1 * first_input_units + 1 * first_input_units) ** 2).units elif unit_op == "square": @@ -217,9 +212,13 @@ def get_numerator_unit(arg): result_unit = first_input_units**size elif unit_op == "invdiv": # Start with first arg in numerator, all others in denominator - numerator_unit = get_numerator_unit(all_args[0]) - denominator_unit = multiply_units(all_args[1:]) - result_unit = (numerator_unit / denominator_unit) ** -1 + product = getattr( + all_args[0], "units", first_input_units._REGISTRY.parse_units("") + ) + for x in all_args[1:]: + if hasattr(x, "units"): + product /= x.units + result_unit = product**-1 else: raise ValueError("Output unit method {} not understood".format(unit_op)) @@ -285,6 +284,12 @@ def implement_func(func_type, func_str, input_units=None, output_unit=None): @implements(func_str, func_type) def implementation(*args, **kwargs): + if (func_str in ["multiply", "true_divide", "divide", "floor_divide"] and + any([_is_sequence_with_quantity_elements(arg) and not _is_quantity(arg) for arg in args])): + # the sequence may contain different units, so fall back to element-wise + print(func_str,args, kwargs) + return np.array([func(args[0][i],args[1][i]) for i in range(len(args[0]))],dtype=object) + first_input_units = _get_first_input_units(args, kwargs) if input_units == "all_consistent": # Match all input args/kwargs to same units @@ -422,7 +427,6 @@ def implementation(*args, **kwargs): "nextafter", "trunc", "absolute", - "positive", "negative", "maximum", "minimum", diff --git a/pint/testsuite/test_issues.py b/pint/testsuite/test_issues.py index 3c1665e04..eddbfbc26 100644 --- a/pint/testsuite/test_issues.py +++ b/pint/testsuite/test_issues.py @@ -892,8 +892,18 @@ def test_issue1674(self, module_registry): arr_of_q = np.array([Q_(2, "m"), Q_(4, "m")], dtype="object") q_arr = Q_(np.array([1, 2]), "m") - helpers.assert_quantity_almost_equal(arr_of_q * q_arr, Q_([2, 8], "m^2")) - helpers.assert_quantity_almost_equal(arr_of_q / q_arr, Q_([2, 2], "")) + helpers.assert_quantity_equal(arr_of_q * q_arr, np.array([Q_(2, "m^2"), Q_(8, "m^2")], dtype="object")) + helpers.assert_quantity_equal(arr_of_q / q_arr, np.array([Q_(2, ""), Q_(2, "")], dtype="object")) + + + arr_of_q = np.array([Q_(2, "m"), Q_(4, "s")], dtype="object") + q_arr = Q_(np.array([1, 2]), "m") + + helpers.assert_quantity_equal( + arr_of_q * q_arr, + np.array([Q_(2, "m^2"), Q_(8, "m s")], dtype="object") + ) + if np is not None: From beba095a9cb9cb8fa301ec4dd0c42a1b15f29b55 Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 23 Jun 2023 21:37:28 +0100 Subject: [PATCH 07/12] undelete positive --- CHANGES | 2 +- pint/facets/numpy/numpy_func.py | 15 +++++++++++---- pint/testsuite/test_issues.py | 15 ++++++++------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/CHANGES b/CHANGES index 469953e31..a9881c124 100644 --- a/CHANGES +++ b/CHANGES @@ -5,7 +5,7 @@ Pint Changelog ----------------- - Documented to_preferred and created added an autoautoconvert_to_preferred registry option. - (PR #1803) + (PR #1803) - Fixed bug causing operations between arrays of quantity scalars and quantity holding array resulting in incorrect units. (PR #1677) diff --git a/pint/facets/numpy/numpy_func.py b/pint/facets/numpy/numpy_func.py index 23168bfeb..cdde04d33 100644 --- a/pint/facets/numpy/numpy_func.py +++ b/pint/facets/numpy/numpy_func.py @@ -284,11 +284,17 @@ def implement_func(func_type, func_str, input_units=None, output_unit=None): @implements(func_str, func_type) def implementation(*args, **kwargs): - if (func_str in ["multiply", "true_divide", "divide", "floor_divide"] and - any([_is_sequence_with_quantity_elements(arg) and not _is_quantity(arg) for arg in args])): + if func_str in ["multiply", "true_divide", "divide", "floor_divide"] and any( + [ + _is_sequence_with_quantity_elements(arg) and not _is_quantity(arg) + for arg in args + ] + ): # the sequence may contain different units, so fall back to element-wise - print(func_str,args, kwargs) - return np.array([func(args[0][i],args[1][i]) for i in range(len(args[0]))],dtype=object) + return np.array( + [func(args[0][i], args[1][i]) for i in range(len(args[0]))], + dtype=object, + ) first_input_units = _get_first_input_units(args, kwargs) if input_units == "all_consistent": @@ -427,6 +433,7 @@ def implementation(*args, **kwargs): "nextafter", "trunc", "absolute", + "positive", "negative", "maximum", "minimum", diff --git a/pint/testsuite/test_issues.py b/pint/testsuite/test_issues.py index be6dc60bd..d939a6521 100644 --- a/pint/testsuite/test_issues.py +++ b/pint/testsuite/test_issues.py @@ -887,18 +887,19 @@ def test_issue1674(self, module_registry): arr_of_q = np.array([Q_(2, "m"), Q_(4, "m")], dtype="object") q_arr = Q_(np.array([1, 2]), "m") - helpers.assert_quantity_equal(arr_of_q * q_arr, np.array([Q_(2, "m^2"), Q_(8, "m^2")], dtype="object")) - helpers.assert_quantity_equal(arr_of_q / q_arr, np.array([Q_(2, ""), Q_(2, "")], dtype="object")) + helpers.assert_quantity_equal( + arr_of_q * q_arr, np.array([Q_(2, "m^2"), Q_(8, "m^2")], dtype="object") + ) + helpers.assert_quantity_equal( + arr_of_q / q_arr, np.array([Q_(2, ""), Q_(2, "")], dtype="object") + ) - arr_of_q = np.array([Q_(2, "m"), Q_(4, "s")], dtype="object") q_arr = Q_(np.array([1, 2]), "m") helpers.assert_quantity_equal( - arr_of_q * q_arr, - np.array([Q_(2, "m^2"), Q_(8, "m s")], dtype="object") - ) - + arr_of_q * q_arr, np.array([Q_(2, "m^2"), Q_(8, "m s")], dtype="object") + ) if np is not None: From 800219e8d7eaa3479645e8aa84d8d21e94fb1f89 Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 23 Jun 2023 22:22:03 +0100 Subject: [PATCH 08/12] np 125 fix --- pint/compat.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pint/compat.py b/pint/compat.py index 6be906f4d..7bb5afb15 100644 --- a/pint/compat.py +++ b/pint/compat.py @@ -303,7 +303,10 @@ def eq(lhs: Any, rhs: Any, check_all: bool) -> Union[bool, Iterable[bool]]: ------- bool or array_like of bool """ - out = lhs == rhs + try: + out = lhs == rhs + except ValueError: + return False if check_all and is_duck_array_type(type(out)): return out.all() return out From b41a096200c2e9e02b4287b79ebf25f2fc1297bf Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 25 Oct 2023 19:10:05 +0100 Subject: [PATCH 09/12] reorder test for performance --- pint/facets/numpy/numpy_func.py | 2 +- pint/testsuite/test_issues.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pint/facets/numpy/numpy_func.py b/pint/facets/numpy/numpy_func.py index bbe149b05..2e37b5f1d 100644 --- a/pint/facets/numpy/numpy_func.py +++ b/pint/facets/numpy/numpy_func.py @@ -286,7 +286,7 @@ def implement_func(func_type, func_str, input_units=None, output_unit=None): def implementation(*args, **kwargs): if func_str in ["multiply", "true_divide", "divide", "floor_divide"] and any( [ - _is_sequence_with_quantity_elements(arg) and not _is_quantity(arg) + not _is_quantity(arg) and _is_sequence_with_quantity_elements(arg) for arg in args ] ): diff --git a/pint/testsuite/test_issues.py b/pint/testsuite/test_issues.py index e3ac956c1..d142e53f8 100644 --- a/pint/testsuite/test_issues.py +++ b/pint/testsuite/test_issues.py @@ -900,7 +900,7 @@ def test_issue1674(self, module_registry): helpers.assert_quantity_equal( arr_of_q * q_arr, np.array([Q_(2, "m^2"), Q_(8, "m s")], dtype="object") ) - + @helpers.requires_babel() def test_issue_1400(self, sess_registry): q1 = 3 * sess_registry.W @@ -961,6 +961,7 @@ def test_issue1614(self, module_registry): assert q2_u.magnitude.std_dev == m2.error assert q2_u.magnitude.std_dev == u2.std_dev + if np is not None: @pytest.mark.filterwarnings("ignore::pint.UnitStrippedWarning") From 8e6be4336c7fd4c1335e04098db8f0208c488b2a Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 25 Oct 2023 20:55:10 +0100 Subject: [PATCH 10/12] revert eq change --- pint/compat.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pint/compat.py b/pint/compat.py index e1164b236..552ff3f7e 100644 --- a/pint/compat.py +++ b/pint/compat.py @@ -302,10 +302,7 @@ def eq(lhs: Any, rhs: Any, check_all: bool) -> Union[bool, Iterable[bool]]: ------- bool or array_like of bool """ - try: - out = lhs == rhs - except ValueError: - return False + out = lhs == rhs if check_all and is_duck_array_type(type(out)): return out.all() return out From 0977c3db0df412d2ad59aff610dc7dd500dafb5d Mon Sep 17 00:00:00 2001 From: andrewgsavage Date: Mon, 13 Nov 2023 13:16:17 +0000 Subject: [PATCH 11/12] Update pint/facets/numpy/numpy_func.py Co-authored-by: Justus Magin --- pint/facets/numpy/numpy_func.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pint/facets/numpy/numpy_func.py b/pint/facets/numpy/numpy_func.py index 2e37b5f1d..4b55bc76f 100644 --- a/pint/facets/numpy/numpy_func.py +++ b/pint/facets/numpy/numpy_func.py @@ -291,10 +291,7 @@ def implementation(*args, **kwargs): ] ): # the sequence may contain different units, so fall back to element-wise - return np.array( - [func(args[0][i], args[1][i]) for i in range(len(args[0]))], - dtype=object, - ) + return np.array([func(*func_args) for func_args in zip(*args)], dtype=object) first_input_units = _get_first_input_units(args, kwargs) if input_units == "all_consistent": From 8bc5fc78e666b60707abeaf45dbeafadf840290a Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 13 Nov 2023 13:26:56 +0000 Subject: [PATCH 12/12] lint --- pint/facets/numpy/numpy_func.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pint/facets/numpy/numpy_func.py b/pint/facets/numpy/numpy_func.py index 4b55bc76f..9862ef857 100644 --- a/pint/facets/numpy/numpy_func.py +++ b/pint/facets/numpy/numpy_func.py @@ -291,7 +291,9 @@ def implementation(*args, **kwargs): ] ): # the sequence may contain different units, so fall back to element-wise - return np.array([func(*func_args) for func_args in zip(*args)], dtype=object) + return np.array( + [func(*func_args) for func_args in zip(*args)], dtype=object + ) first_input_units = _get_first_input_units(args, kwargs) if input_units == "all_consistent":