-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: MaskedArray with nested dtype and object elements cause AttributeError on access #15895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Well, its a bit of a mess. But aside from that, you are right of course. Checking for
and moving the |
So, the purpose of Do we know how |
Ah sorry, this is of course structured access, which is the problem (so the Probably the best thing to do is to get the new dtype directly with |
I have looked into the issue, a little more I have a better understanding of masked array The solution would be something like this? @seberg if self._fill_value.dtype[indx].ndim > 0:
if not (dout._fill_value ==
dout._fill_value.flat[0]).all():
warnings.warn(
"Upon accessing multidimensional field "
f"{indx!s}, need to keep dimensionality "
"of fill_value at 0. Discarding "
"heterogeneous fill_value and setting "
f"all to {dout._fill_value[0]!s}.",
stacklevel=2)
dout._fill_value = dout._fill_value.flat[0]
else:
dout._fill_value = array(self._fill_value[indx]) |
Yeah, something along those lines, although I did not check carefully, and there may be some other tricky stuff lurking. |
When I create a
MaskedArray
using a nested dtype which contains anobject
at the innermost level, trying to access it causes an AttributeError: 'str' object has no attribute 'ndim'.If I use
int
instead ofobject
, the element access works fine.The issue seems to be caused by the assumption that
_fill_value
is of a numpy type and has anndim
attribute.This assumption is true for
numpy.int32
which would be used ifint
was specified inside the dtype.But for
object
, the_fill_value
will be a just pythonstr
'?', which has no attributendim
.I propose to change the code line in question to
Reproducing code example:
Error message:
Numpy/Python version information:
1.18.1 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)]
The text was updated successfully, but these errors were encountered: