summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/function_base.py18
-rw-r--r--numpy/lib/tests/test_function_base.py25
2 files changed, 32 insertions, 11 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 98b0413a1..4172c26b5 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -4530,18 +4530,14 @@ def meshgrid(*xi, **kwargs):
output[1].shape = (-1, 1) + (1,)*(ndim - 2)
shape[0], shape[1] = shape[1], shape[0]
- if sparse:
- if copy_:
- return [x.copy() for x in output]
- else:
- return output
- else:
+ if copy_:
+ output = [x.copy() for x in output]
+
+ if not sparse and len(output) > 0:
# Return the full N-D matrix (not only the 1-D vector)
- if copy_:
- mult_fact = np.ones(shape, dtype=int)
- return [x * mult_fact for x in output]
- else:
- return np.broadcast_arrays(*output)
+ output = np.broadcast_arrays(*output, subok=True)
+
+ return output
def delete(arr, obj, axis=None):
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
index 6327aaf7c..f396e036b 100644
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -2211,6 +2211,7 @@ class TestMeshgrid(TestCase):
def test_no_input(self):
args = []
assert_array_equal([], meshgrid(*args))
+ assert_array_equal([], meshgrid(*args, copy=False))
def test_indexing(self):
x = [1, 2, 3]
@@ -2244,6 +2245,30 @@ class TestMeshgrid(TestCase):
assert_raises(TypeError, meshgrid,
[1, 2, 3], [4, 5, 6, 7], indices='ij')
+ def test_return_type(self):
+ # Test for appropriate dtype in returned arrays.
+ # Regression test for issue #5297
+ # https://github.com/numpy/numpy/issues/5297
+ x = np.arange(0, 10, dtype=np.float32)
+ y = np.arange(10, 20, dtype=np.float64)
+
+ X, Y = np.meshgrid(x,y)
+
+ assert_(X.dtype == x.dtype)
+ assert_(Y.dtype == y.dtype)
+
+ # copy
+ X, Y = np.meshgrid(x,y, copy=True)
+
+ assert_(X.dtype == x.dtype)
+ assert_(Y.dtype == y.dtype)
+
+ # sparse
+ X, Y = np.meshgrid(x,y, sparse=True)
+
+ assert_(X.dtype == x.dtype)
+ assert_(Y.dtype == y.dtype)
+
class TestPiecewise(TestCase):