[AstroPy] Query about Table.add_row() method for masked tables
rborges at hush.com
rborges at hush.com
Fri Oct 2 06:18:49 EDT 2015
Hi Josh!
On Thu, Oct 01, 2015 at 05:30:25PM -0300, 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.)
>
> Josh
>
> In [69]:
> t = Table([[1], [2]], names=('a', 'b'), masked=True)
> t.add_row(None, mask=True)
[...]
> 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: Mismatch between type of vals and mask
I have reproduced your situation.
I believe your goal is: to find a syntax that allows you to append a row of invalid values, that are masked as "True".
I managed to find a solution, as long as it is not relevant that the values be "None"s.
t.add_row( [ 0 for x in t.columns.keys ( ) ], mask = [ True for x in t.columns.keys ( ) ] )
If you try to use "None"s on the first list comprehension, astropy.table complains about the type.
In case you absolutely require 'None's, or find it easier to remember, you can take a two-step approach:
t.add_row ( None )
t.mask [ -1 ] = [ True for x in t.columns.keys ( ) ]
Final note: I am not experienced with atropy.table, so maybe there is a quicker syntax for getting the number of columns.
Hope this helps,
Renato.
More information about the AstroPy
mailing list