File tree 2 files changed +15
-1
lines changed 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -3530,7 +3530,14 @@ def get_fill_value(self):
3530
3530
"""
3531
3531
if self ._fill_value is None :
3532
3532
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
3534
3541
3535
3542
def set_fill_value (self , value = None ):
3536
3543
"""
Original file line number Diff line number Diff line change @@ -1819,6 +1819,13 @@ def test_fillvalue_in_view(self):
1819
1819
y = x .view (dtype = np .int32 )
1820
1820
assert_ (y .fill_value == 999999 )
1821
1821
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
+
1822
1829
1823
1830
class TestUfuncs (TestCase ):
1824
1831
# Test class for the application of ufuncs on MaskedArrays.
You can’t perform that action at this time.
0 commit comments