Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Object-type masked array special-cases elements that are ndarray #18981

Copy link
Copy link
Open
@taldcroft

Description

@taldcroft
Issue body actions

The MaskedArray class has unexpected special-casing of ndarray objects within an object array. I expect an object array to be a generic container of whatever is in each cell, and if that element is masked then accessing it should always return np.ma.masked. Instead MaskedArray appears to turn the ndarray into a fully-masked MaskedArray.

Reproducing code example:

import numpy as np
>>> m = np.ma.array([None, [1, 2], np.array([1, 2])], dtype=object)
>>> m
masked_array(data=[None, list([1, 2]), array([1, 2])],
             mask=False,
       fill_value='?',
            dtype=object)
>>> m.mask = [True, True, True]
>>> m[0]
masked
>>> m[1]
masked
>>> m[2]  # Accessing the ndarray has auto-magically converted it to masked_array
masked_array(data=[--, --],
             mask=[ True,  True],
       fill_value=999999,
            dtype=int64)
>>> m.data[2]  # The data element under the mask is still the original ndarray
array([1, 2])

Expected:

>>> m[2]
masked

Error message:

N/A

NumPy/Python version information:

1.19.5 3.7.9 (default, Aug 31 2020, 07:22:35) 
[Clang 10.0.0 ]

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.