From beba095a9cb9cb8fa301ec4dd0c42a1b15f29b55 Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 23 Jun 2023 21:37:28 +0100 Subject: [PATCH] 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: