Skip to content
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

Incorrect error message when setting element of unmasked array to ma.masked #8461

Closed
gerritholl opened this issue Jan 10, 2017 · 2 comments
Closed

Comments

@gerritholl
Copy link
Contributor

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.
@eric-wieser
Copy link
Member

eric-wieser commented Sep 23, 2017

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

@eric-wieser
Copy link
Member

It gets weirder:

>>> 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants