summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorahaldane <ealloc@gmail.com>2016-02-22 15:14:24 -0500
committerahaldane <ealloc@gmail.com>2016-02-22 15:14:24 -0500
commitbec40c2b7912c4d94894929a2f4aca18c6d344e6 (patch)
tree962f3e5178b7a6d5cc9039b260a1a20f7c4f293b
parentfa3cde1b44182297663c69daa41abb576218a2ab (diff)
parent576b48f00f0fe2a97a7b4dfde2a707d39e8ac099 (diff)
downloadnumpy-bec40c2b7912c4d94894929a2f4aca18c6d344e6.tar.gz
Merge pull request #7260 from gerritholl/fix-structured-masked-array-str
BUG/TST: Fix #7259, do not "force scalar" for already scalar str/bytes
-rw-r--r--numpy/ma/core.py9
-rw-r--r--numpy/ma/tests/test_core.py7
2 files changed, 15 insertions, 1 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index f3d30d15c..72774b820 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -3530,7 +3530,14 @@ class MaskedArray(ndarray):
"""
if self._fill_value is None:
self._fill_value = _check_fill_value(None, self.dtype)
- return self._fill_value[()]
+
+ # Temporary workaround to account for the fact that str and bytes
+ # scalars cannot be indexed with (), whereas all other numpy
+ # scalars can. See issues #7259 and #7267.
+ # The if-block can be removed after #7267 has been fixed.
+ if isinstance(self._fill_value, ndarray):
+ return self._fill_value[()]
+ return self._fill_value
def set_fill_value(self, value=None):
"""
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
index fc8b4bef3..12fb37bec 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -1819,6 +1819,13 @@ class TestFillingValues(TestCase):
y = x.view(dtype=np.int32)
assert_(y.fill_value == 999999)
+ def test_fillvalue_bytes_or_str(self):
+ # Test whether fill values work as expected for structured dtypes
+ # containing bytes or str. See issue #7259.
+ a = empty(shape=(3, ), dtype="(2)3S,(2)3U")
+ assert_equal(a["f0"].fill_value, default_fill_value(b"spam"))
+ assert_equal(a["f1"].fill_value, default_fill_value("eggs"))
+
class TestUfuncs(TestCase):
# Test class for the application of ufuncs on MaskedArrays.