summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorMarten van Kerkwijk <mhvk@astro.utoronto.ca>2018-11-30 11:33:36 -0500
committerMarten van Kerkwijk <mhvk@astro.utoronto.ca>2018-11-30 11:33:36 -0500
commit1842ea98e764d48e4d82636c995b86d1926fd124 (patch)
tree2a8b7c3970c02ae7bf6eb621c662ae86e897d111 /numpy
parentb3a435305082699c26445630d9c79587d51ba9f1 (diff)
downloadnumpy-1842ea98e764d48e4d82636c995b86d1926fd124.tar.gz
BUG: IndexError for empty list on structured MaskedArray.
This should give an empty result, not an error. The problem was that the empty list was interpreted as a list of strings.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/ma/core.py6
-rw-r--r--numpy/ma/tests/test_regression.py5
2 files changed, 8 insertions, 3 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index 4e6469812..96d7207bd 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -780,7 +780,7 @@ def fix_invalid(a, mask=nomask, copy=True, fill_value=None):
def is_string_or_list_of_strings(val):
return (isinstance(val, basestring) or
- (isinstance(val, list) and
+ (isinstance(val, list) and val and
builtins.all(isinstance(s, basestring) for s in val)))
###############################################################################
@@ -6340,7 +6340,7 @@ class MaskedConstant(MaskedArray):
def __copy__(self):
return self
-
+
def __deepcopy__(self, memo):
return self
@@ -7089,7 +7089,7 @@ def where(condition, x=_NoValue, y=_NoValue):
Parameters
----------
condition : array_like, bool
- Where True, yield `x`, otherwise yield `y`.
+ Where True, yield `x`, otherwise yield `y`.
x, y : array_like, optional
Values from which to choose. `x`, `y` and `condition` need to be
broadcastable to some shape.
diff --git a/numpy/ma/tests/test_regression.py b/numpy/ma/tests/test_regression.py
index 96c418a51..67020d8e0 100644
--- a/numpy/ma/tests/test_regression.py
+++ b/numpy/ma/tests/test_regression.py
@@ -84,3 +84,8 @@ class TestRegression(object):
assert_(a.mask.shape == (2,))
assert_(b.shape == (2, 2))
assert_(b.mask.shape == (2, 2))
+
+ def test_empty_list_on_structured(self):
+ # See gh-12464. Indexing with empty list should give empty result.
+ ma = np.ma.MaskedArray([(1, 1.), (2, 2.), (3, 3.)], dtype='i4,f4')
+ assert_array_equal(ma[[]], ma[:0])