summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2020-01-16 04:51:57 +1100
committerEric Wieser <wieser.eric@gmail.com>2020-01-15 17:51:57 +0000
commit87c04cb35aa7eda9372a61cf65939f13d32fa141 (patch)
tree980038d01651ccdc61f0cd90e5b7f1ac41f74994 /numpy
parenta5e5e51187d4476841503ce816924ea99936dba0 (diff)
downloadnumpy-87c04cb35aa7eda9372a61cf65939f13d32fa141.tar.gz
MAINT: Ragged cleanup (#15085)
* TST: refactor sorter tests, use proper ragged array creation syntax * MAINT: code never hit the exception, but would error when iterating * MAINT: pytest.mark.parametrize did not add much, removing (from review) * MAINT: use asanyarray and generalize (from review) Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/tests/test_multiarray.py6
-rw-r--r--numpy/polynomial/polyutils.py12
-rw-r--r--numpy/polynomial/tests/test_polynomial.py8
3 files changed, 14 insertions, 12 deletions
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index d47f1e17e..28e63879b 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -2247,10 +2247,11 @@ class TestMethods:
assert_equal([a.searchsorted(a[i], 'left') for i in ind], ind)
assert_equal([a.searchsorted(a[i], 'right') for i in ind], ind + 1)
- def test_searchsorted_with_sorter(self):
+ def test_searchsorted_with_invalid_sorter(self):
a = np.array([5, 2, 1, 3, 4])
s = np.argsort(a)
- assert_raises(TypeError, np.searchsorted, a, 0, sorter=(1, (2, 3)))
+ assert_raises(TypeError, np.searchsorted, a, 0,
+ sorter=np.array((1, (2, 3)), dtype=object))
assert_raises(TypeError, np.searchsorted, a, 0, sorter=[1.1])
assert_raises(ValueError, np.searchsorted, a, 0, sorter=[1, 2, 3, 4])
assert_raises(ValueError, np.searchsorted, a, 0, sorter=[1, 2, 3, 4, 5, 6])
@@ -2260,6 +2261,7 @@ class TestMethods:
assert_raises(ValueError, np.searchsorted, a, 0, sorter=[-1, 0, 1, 2, 3])
assert_raises(ValueError, np.searchsorted, a, 0, sorter=[4, 0, -1, 2, 3])
+ def test_searchsorted_with_sorter(self):
a = np.random.rand(300)
s = a.argsort()
b = np.sort(a)
diff --git a/numpy/polynomial/polyutils.py b/numpy/polynomial/polyutils.py
index b65e88a83..9b8e9fc42 100644
--- a/numpy/polynomial/polyutils.py
+++ b/numpy/polynomial/polyutils.py
@@ -540,17 +540,15 @@ def _valnd(val_f, c, *args):
c, args :
See the ``<type>val<n>d`` functions for more detail
"""
- try:
- args = tuple(np.array(args, copy=False))
- except Exception:
- # preserve the old error message
- if len(args) == 2:
+ args = [np.asanyarray(a) for a in args]
+ shape0 = args[0].shape
+ if not all((a.shape == shape0 for a in args[1:])):
+ if len(args) == 3:
raise ValueError('x, y, z are incompatible')
- elif len(args) == 3:
+ elif len(args) == 2:
raise ValueError('x, y are incompatible')
else:
raise ValueError('ordinates are incompatible')
-
it = iter(args)
x0 = next(it)
diff --git a/numpy/polynomial/tests/test_polynomial.py b/numpy/polynomial/tests/test_polynomial.py
index c90075dfe..50973c480 100644
--- a/numpy/polynomial/tests/test_polynomial.py
+++ b/numpy/polynomial/tests/test_polynomial.py
@@ -7,7 +7,7 @@ import numpy as np
import numpy.polynomial.polynomial as poly
from numpy.testing import (
assert_almost_equal, assert_raises, assert_equal, assert_,
- assert_warns, assert_array_equal)
+ assert_warns, assert_array_equal, assert_raises_regex)
def trim(x):
@@ -227,7 +227,8 @@ class TestEvaluation:
y1, y2, y3 = self.y
#test exceptions
- assert_raises(ValueError, poly.polyval2d, x1, x2[:2], self.c2d)
+ assert_raises_regex(ValueError, 'incompatible',
+ poly.polyval2d, x1, x2[:2], self.c2d)
#test values
tgt = y1*y2
@@ -244,7 +245,8 @@ class TestEvaluation:
y1, y2, y3 = self.y
#test exceptions
- assert_raises(ValueError, poly.polyval3d, x1, x2, x3[:2], self.c3d)
+ assert_raises_regex(ValueError, 'incompatible',
+ poly.polyval3d, x1, x2, x3[:2], self.c3d)
#test values
tgt = y1*y2*y3