[AstroPy] Query about Table.add_row() method for masked tables

Josh Tan joshuapaultan at gmail.com
Thu Oct 1 16:30:25 EDT 2015


Hello,

I have been trying to use astropy tables and have found that you cannot add a `None` row with a mask. While I can go and add np.zeroes by hand, it’s a bit annoying to me that it behaves this way. (See examples below.)

Josh

In [69]:

t = Table([[1], [2]], names=('a', 'b'), masked=True)
t.add_row(None, mask=True)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-69-4b6f404ff930> in <module>()
      1 t = Table([[1], [2]], names=('a', 'b'), masked=True)
----> 2 t.add_row(None, mask=True)

/Users/joshuaschroeder/Documents/Ureka/python/lib/python2.7/site-packages/astropy/table/table.pyc in add_row(self, vals, mask)
   1623              3   6   9
   1624         """
-> 1625         self.insert_row(len(self), vals, mask)
   1626 
   1627     def insert_row(self, index, vals=None, mask=None):

/Users/joshuaschroeder/Documents/Ureka/python/lib/python2.7/site-packages/astropy/table/table.pyc in insert_row(self, index, vals, mask)
   1674             # that have entries for each table column.
   1675             if mask is not None and not _is_mapping(mask):
-> 1676                 raise TypeError("Mismatch between type of vals and mask")
   1677 
   1678             # Now check that the mask is specified for the same keys as the

TypeError: Mismatch between type of vals and mask

In [74]:

t = Table([[1], [2]], names=('a', 'b'), masked=True)
t.add_row(None, mask=len(t.colnames)*[True])
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-74-ae9160dbf05d> in <module>()
      1 t = Table([[1], [2]], names=('a', 'b'), masked=True)
----> 2 t.add_row(None, mask=len(t.colnames)*[True])

/Users/joshuaschroeder/Documents/Ureka/python/lib/python2.7/site-packages/astropy/table/table.pyc in add_row(self, vals, mask)
   1623              3   6   9
   1624         """
-> 1625         self.insert_row(len(self), vals, mask)
   1626 
   1627     def insert_row(self, index, vals=None, mask=None):

/Users/joshuaschroeder/Documents/Ureka/python/lib/python2.7/site-packages/astropy/table/table.pyc in insert_row(self, index, vals, mask)
   1674             # that have entries for each table column.
   1675             if mask is not None and not _is_mapping(mask):
-> 1676                 raise TypeError("Mismatch between type of vals and mask")
   1677 
   1678             # Now check that the mask is specified for the same keys as the

TypeError: Mismatch between type of vals and mask

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20151001/3c1242d3/attachment.html>


More information about the AstroPy mailing list