Skip to content

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

Closed

Description

@gerritholl

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.

Activity

  1. eric-wieser commented on Sep 23, 2017

    @eric-wieser
    Member

    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

  2. eric-wieser commented on Sep 23, 2017

    @eric-wieser
    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.
    
  3. added a commit that references this issue on Oct 23, 2017
    6252c2d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions