summaryrefslogtreecommitdiff
path: root/pint
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 /pint
parenta01007c67b5ce532536994d556853ff163362ba8 (diff)
parent9db2b295e3bc4b5e67ce0f0b0651533281139844 (diff)
downloadpint-f9993d0088b18929002586406e2e805bf6c43abb.tar.gz
Merge branch 'master' into ndim
Diffstat (limited to 'pint')
-rw-r--r--pint/facets/numpy/numpy_func.py6
-rw-r--r--pint/testsuite/test_numpy.py12
2 files changed, 18 insertions, 0 deletions
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(