summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpierregm <pierregm@localhost>2009-08-30 18:08:08 +0000
committerpierregm <pierregm@localhost>2009-08-30 18:08:08 +0000
commitbbe188eeb0b87d5ea08e2f142651d9cd1de652cd (patch)
treeeb549ae9c28888a04f0df9b76d4e045c58691798
parentcb955806a508ec15ebb83fa358f63a9dc67f7a16 (diff)
downloadnumpy-bbe188eeb0b87d5ea08e2f142651d9cd1de652cd.tar.gz
* Bugfix for ticket #1207
-rw-r--r--numpy/ma/core.py2
-rw-r--r--numpy/ma/tests/test_core.py8
2 files changed, 9 insertions, 1 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index 3071ff5fe..8321c5d1d 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -5309,7 +5309,7 @@ def where (condition, x=None, y=None):
elif y is masked:
ndtype = xv.dtype
else:
- ndtype = np.max([xv.dtype, yv.dtype])
+ ndtype = np.find_common_type([xv.dtype, yv.dtype], [])
# Construct an empty array and fill it
d = np.empty(fc.shape, dtype=ndtype).view(MaskedArray)
_data = d._data
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
index dc37ff4b6..286090ad8 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -2787,6 +2787,14 @@ class TestMaskedArrayFunctions(TestCase):
z = where(c, 1, masked)
assert_equal(z, [99, 1, 1, 99, 99])
+ def test_where_type(self):
+ "Test the type conservation with where"
+ x = np.arange(4, dtype=np.int32)
+ y = np.arange(4, dtype=np.float32) * 2.2
+ test = where(x > 1.5, y, x).dtype
+ control = np.find_common_type([np.int32, np.float32], [])
+ assert_equal(test, control)
+
def test_choose(self):
"Test choose"