Skip to content

Mask from MaskedColumn is not copied #7362

Closed

Description

@saimn

When copying a masked table, the mask of MaskedColumn objects is not copied, which leads to weird result:

In [1]: %astropy
Numpy 1.14.2
Astropy 3.1.dev21681

In [2]: t = Table([[2,4,1,3,6], [3.,2.,np.nan,4,6]], names=('a', 'b'), masked=True)

In [3]: t['b'] = np.ma.masked_invalid(t['b'])

In [4]: t
Out[4]: 
<Table masked=True length=5>
  a      b   
int64 float64
----- -------
    2     3.0
    4     2.0
    1      --
    3     4.0
    6     6.0

In [5]: t2 = t.copy()

In [6]: t2.sort('a')

In [7]: t2
Out[7]: 
<Table masked=True length=5>
  a      b   
int64 float64
----- -------
    1      --
    2     3.0
    3     4.0
    4     2.0
    6     6.0

In [8]: t
Out[8]: 
<Table masked=True length=5>
  a      b   
int64 float64
----- -------
    2      --
    4     2.0
    1     nan
    3     4.0
    6     6.0

Looking at https://github.com/astropy/astropy/blob/master/astropy/table/column.py#L1122-L1133, It seems that the data is copied but not the mask. Maybe @mhvk ?

Activity

  1. yannick1974 commented on Apr 11, 2018

    @yannick1974

    Note that the problem exists when using numpy 1.14.2 but not numpy 1.13.3. Probably linked to https://docs.scipy.org/doc/numpy/release.html#compatibility-notes

  2. saimn commented on Apr 11, 2018

    @saimn
    ContributorAuthor

    Yes indeed, it is due to the fact that the mask is no more always copied (related to #5060, #5530).

  3. added a commit that references this issue on May 22, 2018
    5079689
  4. added a commit that references this issue on Sep 18, 2018
    617462e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions