summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandrewgsavage <andrewgsavage@gmail.com>2022-10-08 00:45:23 +0100
committerGitHub <noreply@github.com>2022-10-08 00:45:23 +0100
commitf9993d0088b18929002586406e2e805bf6c43abb (patch)
tree4bf2f72b2d78f716ede28e627b419d9a79b37df4
parenta01007c67b5ce532536994d556853ff163362ba8 (diff)
parent9db2b295e3bc4b5e67ce0f0b0651533281139844 (diff)
downloadpint-f9993d0088b18929002586406e2e805bf6c43abb.tar.gz
Merge branch 'master' into ndim
-rw-r--r--CHANGES5
-rw-r--r--pint/facets/numpy/numpy_func.py6
-rw-r--r--pint/testsuite/test_numpy.py12
3 files changed, 22 insertions, 1 deletions
diff --git a/CHANGES b/CHANGES
index 7e46439..254a2c0 100644
--- a/CHANGES
+++ b/CHANGES
@@ -11,7 +11,10 @@ Pint Changelog
(Issue #1030, #574)
- Added angular frequency documentation page.
- Move ASV benchmarks to dedicated folder. (Issue #1542)
-- An ndim attribute has been added to Quantity and DataFrame has been added to upcast types for pint-pandas compatibility. (#1596)
+- An ndim attribute has been added to Quantity and DataFrame has been added to upcast
+types for pint-pandas compatibility. (#1596)
+- Fix a recursion error that would be raised when passing quantities to `cond` and `x`.
+ (Issue #1510, #1530)
0.19.2 (2022-04-23)
-------------------
diff --git a/pint/facets/numpy/numpy_func.py b/pint/facets/numpy/numpy_func.py
index 7143143..59c2f98 100644
--- a/pint/facets/numpy/numpy_func.py
+++ b/pint/facets/numpy/numpy_func.py
@@ -552,6 +552,12 @@ def _interp(x, xp, fp, left=None, right=None, period=None):
@implements("where", "function")
def _where(condition, *args):
+ if not getattr(condition, "_is_multiplicative", True):
+ raise ValueError(
+ "Invalid units of the condition: Boolean value of Quantity with offset unit is ambiguous."
+ )
+
+ condition = getattr(condition, "magnitude", condition)
args, output_wrap = unwrap_and_wrap_consistent_units(*args)
return output_wrap(np.where(condition, *args))
diff --git a/pint/testsuite/test_numpy.py b/pint/testsuite/test_numpy.py
index f2ddaf0..77d18e3 100644
--- a/pint/testsuite/test_numpy.py
+++ b/pint/testsuite/test_numpy.py
@@ -1103,6 +1103,18 @@ class TestNumpyUnclassified(TestNumpyMethods):
0 * self.ureg.J,
)
+ helpers.assert_quantity_equal(
+ np.where([-1, 0, 1] * self.ureg.m, [1, 2, 1] * self.ureg.s, np.nan),
+ [1, np.nan, 1] * self.ureg.s,
+ )
+ with pytest.raises(
+ ValueError,
+ match=".*Boolean value of Quantity with offset unit is ambiguous",
+ ):
+ np.where(
+ self.ureg.Quantity([-1, 0, 1], "degC"), [1, 2, 1] * self.ureg.s, np.nan
+ )
+
@helpers.requires_array_function_protocol()
def test_fabs(self):
helpers.assert_quantity_equal(