Adding columns to astropy table in sort_query_results_4_11.ipynb
While running sort_query_results_4-11.ipynb with Python 3.7 I encountered an error while adding columns in block [12]: of
the Jupyter notebook. See the text file with the error output.
It seems that while the code must have run earlier the add_column() method now requires for the Quantity object that the length of the object needs to be specified.
I was able to fix this by specifying the length. Here is a snippet of example code:
# An example notebook to create a table and add a column with units in a similar fashion to
# what happens in [12]; of sort_query_results_4_11.ipynb
# Import what is needed
import numpy as np # arrays aere needed
from astropy import units as u # units are needed
from astropy.table import Table # using Table of course
# Make a 5 row by 3 column array
arr = np.arange(15).reshape(5, 3)
# Now place the array into a table called 't' primed to accept meta data:=
t = Table(arr, names=('a', 'b', 'c'), meta={'keywords': {'key1': 'val1'}})
# add a column calling it 'd1' with range of values 0->4
t['d1'] = np.arange(5)
t[0:3]['c'] = 100
# Add units of parsec as 'pc' to column c
# and units of 'm' to column a and 's' to col. b
# units of d1 to centimeters and see what the table looks
# like now.
t['c'] = t['c']*u.pc
t['b'] = t['b']*u.s
t['a'] = t['a']*u.m
t[0:3]['c'] = 100
t['d1'] = t['d1']*u.cm
# Try to add a column as it is done now in sort_query_results_4_11.ipynb
# Index is not specified so this column will be appended to the end.
t.add_column(0.0*u.arcsec, name='separation')
The line above throws the error
# Now try adding this column but fix the length issue by using the np.array
# to set the length
t.add_column(np.arange(1.,6.)*u.arcsec, name='separation')
# show the table
t
The code above worked for me.
Changes coming
I propose this issue as a bug (sorry Daphne!) and will apply the changes so that columns are added
by specifying the length of the array required.
Adding columns to astropy table in sort_query_results_4_11.ipynb
While running sort_query_results_4-11.ipynb with Python 3.7 I encountered an error while adding columns in block [12]: of the Jupyter notebook. See the text file with the error output.
adding_tables_error.ipynb.txt
It seems that while the code must have run earlier the
add_column()
method now requires for the Quantity object that the length of the object needs to be specified.I was able to fix this by specifying the length. Here is a snippet of example code:
The line above throws the error
The code above worked for me.
Changes coming
I propose this issue as a bug (sorry Daphne!) and will apply the changes so that columns are added by specifying the length of the array required.