You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fill_value attribute gives TypeError for structured masked array fields with character dtype #7259
For a structured masked array, when accessing a field with a character dtype, the fill_value is evidently not correctly set. When X is a structured masked array with a structured dtype such that field A is a character array, accessing X['A'].fill_value gives TypeError: byte indices must be integers or slices, not tuple. The offending line of code is:
return self._fill_value[()]
with a full example shown below.
$ ipython3 --pylab
Python 3.5.0 (default, Nov 20 2015, 16:20:41)
Type "copyright", "credits" or "license" for more information.
IPython 4.0.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
Using matplotlib backend: TkAgg
Python are go!
In [1]: print(numpy.version.version)
1.12.0.dev0+0de1234
In [2]: X = numpy.ma.empty(shape=1, dtype=[("A", "S1", 2)])
In [3]: Xa = X["A"]
In [5]: Xa.fill_value
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-d077d77d307b> in <module>()
----> 1 Xa.fill_value
/home/users/gholl/venv/stable-3.5/lib/python3.5/site-packages/numpy/ma/core.py in get_fill_value(self)
3528 if self._fill_value is None:
3529 self._fill_value = _check_fill_value(None, self.dtype)
-> 3530 return self._fill_value[()]
3531
3532 def set_fill_value(self, value=None):
TypeError: byte indices must be integers or slices, not tuple
This problem is triggered, among other locations, upon calling repr(Xa), so it has a rather high impact in practice.
It appears to be ultimately due to the fact that most numpy scalars are valid to be indexed with (), but numpy.bytes_ is not:
In [36]: numpy.int64(10)[()]
Out[36]: 10
In [37]: numpy.bytes_("ABC")
Out[37]: b'ABC'
In [38]: numpy.bytes_("ABC")[()]
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-38-4912a5675720> in <module>()
----> 1 numpy.bytes_("ABC")[()]
TypeError: byte indices must be integers or slices, not tuple
Activity
gerritholl commentedon Feb 16, 2016
It appears to be ultimately due to the fact that most numpy scalars are valid to be indexed with
(), butnumpy.bytes_is not:* Force _fill_value to a 0d array (so that field values can be propag…
gerritholl commentedon Feb 16, 2016
See also my comment on the commit triggering this problem: f8f753b#commitcomment-16120218
Merge pull request #7260 from gerritholl/fix-structured-masked-array-str
BUG/TST: Fix numpy#7259, do not "force scalar" for already scalar str…