Skip to content

Commit 62f0c00

Browse files
Merge #683
683: BUG: Fix using Quantity with numpy.searchsorted r=hgrecco a=dopplershift The method on Quantity was not up to date with the numpy set of arguments, which [as of 1.7](https://docs.scipy.org/doc/numpy/reference/generated/numpy.searchsorted.html?highlight=searchsorted#numpy.searchsorted) includes a `sorter` argument. Adding this allows the numpy function to properly delegate to the Quantity method. Co-authored-by: Ryan May <[email protected]>
2 parents 241bf7d + 541d9af commit 62f0c00

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

pint/quantity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,7 @@ def shape(self):
12931293
def shape(self, value):
12941294
self._magnitude.shape = value
12951295

1296-
def searchsorted(self, v, side='left'):
1296+
def searchsorted(self, v, side='left', sorter=None):
12971297
if isinstance(v, self.__class__):
12981298
v = v.to(self).magnitude
12991299
elif self.dimensionless:

pint/testsuite/test_numpy.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ def test_searchsorted(self):
113113
q = self.q.flatten()
114114
self.assertRaises(ValueError, q.searchsorted, [1.5, 2.5])
115115

116+
def test_searchsorted_numpy_func(self):
117+
"""Test searchsorted as numpy function."""
118+
q = self.q.flatten()
119+
np.testing.assert_array_equal(np.searchsorted(q, [1.5, 2.5] * self.ureg.m),
120+
[1, 2])
121+
116122
def test_nonzero(self):
117123
q = [1, 0, 5, 6, 0, 9] * self.ureg.m
118124
np.testing.assert_array_equal(q.nonzero()[0], [0, 2, 3, 5])

0 commit comments

Comments
 (0)