[AstroPy] Query about Table.add_row() method for masked tables
Thomas Robitaille
thomas.robitaille at gmail.com
Sun Oct 4 12:28:38 EDT 2015
Hi Josh,
The following should work:
In [8]: t = Table([[1], [2]], names=('a','b'), masked=True)
In [9]: t.add_row({})
In [10]: t
Out[10]:
<Table masked=True length=2>
a b
int64 int64
----- -----
1 2
-- --
Is this what you need?
Cheers,
Tom
Erik Bray wrote:
> On 10/1/2015 4:30 PM, Josh Tan wrote:
>> 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.)
>
> Hi Josh,
>
> There definitely seems to be some conflict between add_row(None) and
> add_row(..., mask=...). It seems to be that the allowed formats for the
> mask value aren't really compatible with the add_row(None) syntax. I
> think that could be fixed--the way you were trying to do it,
> add_row(None, mask=True), makes sense to me.
>
> Erik
>
>> 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)
>> ----> 2t.add_row(None, mask=True)
>>
>> /Users/joshuaschroeder/Documents/Ureka/python/lib/python2.7/site-packages/astropy/table/table.pyc
>> inadd_row(self, vals, mask) 1623 3 6 9
>> 1624 """
>> -> 1625self.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
>> ininsert_row(self, index, vals, mask) 1674 # that have entries for
>> each table column.
>> 1675 if maskis not Noneand not _is_mapping(mask):
>> -> 1676raise 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)
>> ----> 2t.add_row(None, mask=len(t.colnames)*[True])
>>
>> /Users/joshuaschroeder/Documents/Ureka/python/lib/python2.7/site-packages/astropy/table/table.pyc
>> inadd_row(self, vals, mask) 1623 3 6 9
>> 1624 """
>> -> 1625self.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
>> ininsert_row(self, index, vals, mask) 1674 # that have entries for
>> each table column.
>> 1675 if maskis not Noneand not _is_mapping(mask):
>> -> 1676raise 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
>>
>>
>>
>>
>> _______________________________________________
>> AstroPy mailing list
>> AstroPy at scipy.org
>> https://mail.scipy.org/mailman/listinfo/astropy
>>
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> https://mail.scipy.org/mailman/listinfo/astropy
More information about the AstroPy
mailing list