summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalf Gommers <ralf.gommers@googlemail.com>2011-12-28 10:01:42 +0100
committerRalf Gommers <ralf.gommers@googlemail.com>2011-12-28 10:01:42 +0100
commit4e571172a210612bdeba1db0135b7d5fbc44ee0c (patch)
treeac5862fc0e228b85b69aeabb2d0d34581456b177
parent37d723cb629e3e8cb4d9ed7b85702fbd6350818d (diff)
downloadnumpy-4e571172a210612bdeba1db0135b7d5fbc44ee0c.tar.gz
BUG: meshgrid: raise error on single input.
-rw-r--r--numpy/lib/function_base.py9
-rw-r--r--numpy/lib/tests/test_function_base.py4
2 files changed, 9 insertions, 4 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index abb239ffc..8e2fc375e 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -3288,13 +3288,14 @@ def meshgrid(*xi, **kwargs):
"""
copy_ = kwargs.get('copy', True)
+
+ if len(xi) < 2:
+ msg = 'meshgrid() takes 2 or more arguments (%d given)' % int(len(xi) > 0)
+ raise ValueError(msg)
+
args = np.atleast_1d(*xi)
ndim = len(args)
- if ndim < 2:
- msg = 'meshgrid() takes 2 or more arguments (%d given)' % int(ndim > 0)
- raise TypeError(msg)
-
sparse = kwargs.get('sparse', False)
indexing = kwargs.get('indexing', 'xy')
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
index 83532e70d..eda919df6 100644
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -1025,6 +1025,10 @@ class TestMeshgrid(TestCase):
[5, 5, 5],
[6, 6, 6],
[7, 7, 7]])))
+
+ def test_single_input(self):
+ assert_raises(ValueError, meshgrid, np.arange(5))
+
def test_indexing(self):
[X, Y] = meshgrid([1, 2, 3], [4, 5, 6, 7], indexing='ij')
assert_(all(X == array([[1, 1, 1, 1],