Skip to content

np.copy(masked array) has unexpected behavior #3474

@keflavich

Description

@keflavich

....where "unexpected" means I didn't expect it. This may just be a documentation fix, or maybe I will be scolded for not realizing how np.ma works, but I don't think this behavior is appropriate:

In [100]: x = np.ma.ones(5)

In [101]: x.mask = [False,False,True,False,False]

In [102]: np.copy(x)
Out[102]: array([ 1.,  1.,  1.,  1.,  1.])

In [103]: np.ma.copy(x)
Out[103]:
masked_array(data = [1.0 1.0 -- 1.0 1.0],
             mask = [False False  True False False],
       fill_value = 1e+20)

In [104]: np.__version__
Out[104]: '1.8.0.dev-074a40c'

I would at least expect a warning, but would prefer to see, in order of preference:

  • np.copy(x) returns a masked array (since x is a masked array)
  • np.copy(x) warns that it is unmasking the array, then returns the same array as above
  • np.copy(x) raises an exception
  • np.copy(x) returns [1,1,nan,1,1] (this is probably not ideal)

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