Skip to content

Setting masked column on non-masked table should raise error #4675

Closed

Description

@saimn

Somewhat similar to #3505, I find this behavior surprising:

In [4]: t = Table([[1,2,3]], names='a')       

In [5]: t
Out[5]: 
<Table length=3>
  a  
int64
-----
    1
    2
    3

In [6]: t['a'] = MaskedColumn(data=[1,2,3], name='a', mask=[True, False,False])                                                                                                         

In [7]: t
Out[7]: 
<Table length=3>
  a  
int64
-----
    1
    2
    3

This is due to Numpy's behavior (setting values from a masked array to a normal copies the values and discards the mask), but maybe it should be prevented ?

Activity

  1. astrofrog commented on Apr 19, 2016

    @astrofrog
    Member

    @saimn - I think maybe it should work but raise a warning if any of the mask values are True. I can think of a use case where a user reads a table from a file and it happens to return a maskedcolumn but with no actual masked values.

    @taldcroft - what do you think?

  2. pllim commented on Apr 19, 2016

    @pllim
    Member

    @astrofrog , I agree with you.

  3. saimn commented on Apr 19, 2016

    @saimn
    ContributorAuthor

    Yes, a warning is fine also, I have no strong preference.

  4. taldcroft commented on Apr 19, 2016

    @taldcroft
    Member

    @saimn - I'm -0.5 on raising a warning like this. As you said this is really an upstream issue since the implementation here is completely delegating to numpy:

                if isinstance(item, six.string_types):
                    # Set an existing column
                    self.columns[item][:] = value
    

    I think that this is really another instance of being surprised that when you set a column it does an in-place assignment instead of overwriting the entire column. Numpy structured array shares this behavior. Once you have that in your head, then it should not be surprising that when you assign a masked array to an unmasked Column then the result will not have masked values.

    Interestingly, Pandas does mutate column types on demand...

  5. taldcroft commented on Apr 20, 2016

    @taldcroft
    Member

    BTW, I was just playing around with pandas and I find it's dtype-changing behavior either confusing or maybe downright buggy:

    In [68]: df['a'] = pd.Series([4,5], dtype=np.float32)
    
    In [69]: df['a'].dtype
    Out[69]: dtype('float32')
    
    In [70]: df['a'][:] = np.array([1,2], dtype=np.float64)
    
    In [71]: df['a'].dtype
    Out[71]: dtype('int64')  # What the heck?!?
    
    In [72]: df['a'] = np.array([1,2], dtype=np.float64)
    
    In [73]: df['a'].dtype
    Out[73]: dtype('float64')
    
  6. saimn commented on May 1, 2018

    @saimn
    ContributorAuthor

    Closing this old issue, as I agree that the behavior is consistent with Numpy.

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