10000 Merge pull request #7260 from gerritholl/fix-structured-masked-array-str · numpy/numpy@bec40c2 · GitHub
[go: up one dir, main page]

Skip to content

Commit bec40c2

Browse files
committed
Merge pull request #7260 from gerritholl/fix-structured-masked-array-str
BUG/TST: Fix #7259, do not "force scalar" for already scalar str/bytes
2 parents fa3cde1 + 576b48f commit bec40c2

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

numpy/ma/core.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3530,7 +3530,14 @@ def get_fill_value(self):
35303530
"""
35313531
if self._fill_value is None:
35323532
self._fill_value = _check_fill_value(None, self.dtype)
3533-
return self._fill_value[()]
3533+
3534+
# Temporary workaround to account for the fact that str and bytes
3535+
# scalars cannot be indexed with (), whereas all other numpy
3536+
# scalars can. See issues #7259 and #7267.
3537+
# The if-block can be removed after #7267 has been fixed.
3538+
if isinstance(self._fill_value, ndarray):
3539+
return self._fill_value[()]
3540+
return self._fill_value
35343541

35353542
def set_fill_value(self, value=None):
35363543
"""

numpy/ma/tests/test_core.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,6 +1819,13 @@ def test_fillvalue_in_view(self):
18191819
y = x.view(dtype=np.int32)
18201820
assert_(y.fill_value == 999999)
18211821

1822+
def test_fillvalue_bytes_or_str(self):
1823+
# Test whether fill values work as expected for structured dtypes
1824+
# containing bytes or str. See issue #7259.
1825+
a = empty(shape=(3, ), dtype="(2)3S,(2)3U")
1826+
assert_equal(a["f0"].fill_value, default_fill_value(b"spam"))
1827+
assert_equal(a["f1"].fill_value, default_fill_value("eggs"))
1828+
18221829

18231830
class TestUfuncs(TestCase):
18241831
# Test class for the application of ufuncs on MaskedArrays.

0 commit comments

Comments
 (0)
0