question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't add row to table with, e.g., SkyCoord column

See original GitHub issue

Starting with the documented way of making a table:

from astropy.table import Table
from astropy.time import Time
from astropy.coordinates import SkyCoord
tm = Time(['2000:002', '2002:345'])
sc = SkyCoord([10, 20], [-45, +40], unit='deg')
t = Table([tm, sc], names=['time', 'skycoord'])
print(t)

gives

         time          skycoord
                       deg,deg
--------------------- ----------
2000:002:00:00:00.000 10.0,-45.0
2002:345:00:00:00.000  20.0,40.0

But if I try to add another row:

# Add another row
t.add_row((Time('2017:001'),sc[0]))

I get

ValueError: Unable to insert row because of exception in column 'time':
'Time' object has no attribute 'insert'

Trying different things:

t = Table([[tm[0]],[sc[0]]], names=['time', 'skycoord'])
t.add_row([tm[1],sc[1]])

works giving:

         time                               skycoord                      
--------------------- ----------------------------------------------------
2000:002:00:00:00.000 <SkyCoord (ICRS): (ra, dec) in deg
    ( 10., -45.)>
2002:345:00:00:00.000 <SkyCoord (ICRS): (ra, dec) in deg
    ( 20.,  40.)>

So if you use astropy array objects, you can’t add rows. But if you use scalar values, you can add rows and later extract the values as a list .

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
bsipoczcommented, Mar 9, 2019

Or, should I look into adding an insert() method for SkyCoord?

I would naively say yes, but let’s ping the coordinates maintainers @eteq @adrn to comment on it.

0reactions
kakirasterncommented, Mar 10, 2019

I have a feeling that the code involved to introduce an insert property to SkyCoord would be a lot more complicated than for either Time or Quantity

Read more comments on GitHub >

github_iconTop Results From Across the Web

SkyCoord — Astropy v5.2
A convenience method to create and return a new SkyCoord from the data in an astropy Table. This method matches table columns that...
Read more >
Table — Astropy v5.2
Add a new row to the end of the table. The vals argument can be: sequence (e.g. tuple or list). Column values in...
Read more >
Source code for astropy.table.operations
Convert inputs (Table, Row, or anything column-like) to Tables. ... TypeError) as err: raise TypeError(f'Cannot convert {val} to table column.
Read more >
Table Operations — Astropy v5.2
The groups property is the portal to all grouped operations with tables and columns. It defines how the table is grouped via an...
Read more >
Constructing a Table — Astropy v5.2
These can be used to create a Table by putting the column data variables ... a new table by selecting columns and putting...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found