<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Apr 29, 2015 at 1:40 PM, Alexa Villaume <span dir="ltr"><<a href="mailto:avillaum@ucsc.edu" target="_blank">avillaum@ucsc.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi everybody,<br>
<br>
I’m trying to construct an astropy table using the exact same columns and corresponding dtypes of an existing table. The documentation goes into using existing columns but it wasn’t as clear to me on how to handle the data types. For example, I have an existing table ‘irtf’ and I want to make a table ‘irtf_hb’ if I do,<br>
<br>
irtf_hb = Table(names=irtf.colnames)<br>
<br>
the table is initialized with all the right column names but the dtypes are all floats. However, I can’t do this,<br>
<br>
irtf_hb = Table(names=irtf.colnames, dtype=irtf.dtype)<br>
<br>
Because I get an error, “ValueError: dtype must be a list or None”. I haven’t had any luck with trying to change the type of irtf.dtype or using list comprehension to extract a list of dtypes.<br>
<br>
Is there a simple way to use the dtypes of an existing table to initialize a new table?<br></blockquote><div><br></div><div>You should be able to do:</div><div><br></div><div>>>> irtf_hb = Table(irtf[0:0])</div><div><br></div><div>This is a slight hack, but it's pretty simple and should give you a zero-length table with all the original table properties.  I tested on a simple case but haven't checked in detail.</div><div><br></div><div><div>In [3]: from astropy.table import Table</div><div><br></div><div>In [4]: t = Table([[1]])<br></div><div><br></div><div>In [5]: t2 = Table(t[0:0])<br></div><div><br></div><div>In [6]: t2<br></div><div>Out[6]: </div><div><Table masked=False length=0></div><div> col0</div><div>int64</div><div>-----</div><div><br></div><div>In [7]: </div></div><div><br></div><div>- Tom</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
Thank you,<br>
Alexa<br>
_______________________________________________<br>
AstroPy mailing list<br>
<a href="mailto:AstroPy@scipy.org">AstroPy@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/astropy" target="_blank">http://mail.scipy.org/mailman/listinfo/astropy</a><br>
</blockquote></div><br></div></div>