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
Incorrect error message when setting element of unmasked array to ma.masked #8461
When setting an element of an unmasked array to ma.masked, the error message is ValueError: setting an array element with a sequence.. This error message is confusing or outright wrong. The same error message happens in other contexts, for example, if warning are turned to errors then UserWarning: converting masked element to nan becomes the same error message.
In [301]: A = arange(5)
In [303]: A[0] = ma.masked
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-303-286b16dc7aa0> in <module>()
----> 1 A[0] = ma.masked
ValueError: setting an array element with a sequence.
This is super weird. Ultimately, the problem is that ->f->setitem on numeric types does not know how to handle 0d arrays. The bug doesn't exist for string types, because that setitem handler does know how to deal with it (as of #8903).
It's not clear to me how we end up calling setitem here at all - there's something special going on with masked that I can't reproduce with a plain 0d array
>>> a = np.zeros(2)
>>> a[0] = np.ma.masked
ValueError: setting an array element with a sequence.
>>> b = np.zeros((2, 2))
>>> b[0] = np.ma.masked
UserWarning: Warning: converting a masked element to nan.
Activity
eric-wieser commentedon Sep 23, 2017
This is super weird. Ultimately, the problem is that
->f->setitemon numeric types does not know how to handle 0d arrays. The bug doesn't exist for string types, because thatsetitemhandler does know how to deal with it (as of #8903).It's not clear to me how we end up calling
setitemhere at all - there's something special going on withmaskedthat I can't reproduce with a plain 0d arrayeric-wieser commentedon Sep 23, 2017
It gets weirder:
BUG: Errors thrown by 0d arrays in setitem are silenced and replaced