summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/lib/function_base.py23
-rw-r--r--numpy/lib/tests/test_function_base.py19
2 files changed, 15 insertions, 27 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 30349f9e5..6009b0e4b 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -2287,23 +2287,12 @@ class vectorize:
def __init__(self, pyfunc=np._NoValue, otypes=None, doc=None,
excluded=None, cache=False, signature=None):
- if not callable(pyfunc):
- p_temp = pyfunc
- pyfunc = np._NoValue
- if p_temp is not None and p_temp is not np._NoValue:
- o_temp = otypes
- otypes = p_temp
- if o_temp is not None:
- d_temp = doc
- doc = o_temp
- if d_temp is not None:
- e_temp = excluded
- excluded = d_temp
- if e_temp is True or e_temp is False:
- c_temp = cache
- cache = e_temp
- if c_temp is not None:
- signature = c_temp
+ if (pyfunc != np._NoValue) and (not callable(pyfunc)):
+ #Splitting the error message to keep
+ #the length below 79 characters.
+ part1 = "When used as a decorator, "
+ part2 = "only accepts keyword arguments."
+ raise TypeError(part1 + part2)
self.pyfunc = pyfunc
self.cache = cache
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
index b56d776cb..416a9431b 100644
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -1817,16 +1817,15 @@ class TestVectorize:
assert_array_equal(r, [1, 2, 3])
assert f.__name__ == 'f'
- def test_decorator_positional_args(self):
- A = np.vectorize(abs, ['float64'], "return float absolute value")
- y1 = A([1, -1, 0, 0.3, 5])
-
- @vectorize(['float64'], "return float absolute value")
- def myabs(a):
- return abs(a)
-
- y2 = myabs([1, -1, 0, 0.3, 5])
- assert_array_equal(y1, y2)
+ def test_bad_input(self):
+ with assert_raises(TypeError):
+ A = np.vectorize(pyfunc = 3)
+
+ def test_no_keywords(self):
+ with assert_raises(TypeError):
+ @np.vectorize("string")
+ def foo():
+ return "bar"
def test_positional_regression_9477(self):
# This supplies the first keyword argument as a positional,