<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>You beat me to the punch, Tom, I was going to suggest exactly this. Numpys built-in empty_like method is extremely convenient, and it would be great to have an analogous astropy table method. </div><div><br></div><div><br><div><div>On Apr 29, 2015, at 2:21 PM, Thomas Robitaille <<a href="mailto:thomas.robitaille@gmail.com">thomas.robitaille@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">On 29 April 2015 at 19:19, Aldcroft, Thomas<br><<a href="mailto:aldcroft@head.cfa.harvard.edu">aldcroft@head.cfa.harvard.edu</a>> wrote:<br><blockquote type="cite"><br><br>On Wed, Apr 29, 2015 at 2:13 PM, Aldcroft, Thomas<br><<a href="mailto:aldcroft@head.cfa.harvard.edu">aldcroft@head.cfa.harvard.edu</a>> wrote:<br><blockquote type="cite"><br><br><br>On Wed, Apr 29, 2015 at 1:40 PM, Alexa Villaume <<a href="mailto:avillaum@ucsc.edu">avillaum@ucsc.edu</a>> wrote:<br><blockquote type="cite"><br>Hi everybody,<br><br>I’m trying to construct an astropy table using the exact same columns and<br>corresponding dtypes of an existing table. The documentation goes into using<br>existing columns but it wasn’t as clear to me on how to handle the data<br>types. For example, I have an existing table ‘irtf’ and I want to make a<br>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<br>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<br>haven’t had any luck with trying to change the type of irtf.dtype or using<br>list comprehension to extract a list of dtypes.<br><br>Is there a simple way to use the dtypes of an existing table to<br>initialize a new table?<br></blockquote><br><br>You should be able to do:<br><br><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">irtf_hb = Table(irtf[0:0])<br></blockquote></blockquote></blockquote><br>This is a slight hack, but it's pretty simple and should give you a<br>zero-length table with all the original table properties.  I tested on a<br>simple case but haven't checked in detail.<br></blockquote><br><br>BTW, "all the original table properties" includes all column and table meta<br>data (e.g. units), so this should be the preferred idiom.<br></blockquote><br>How about a new class method that does something like<br>``np.empty_like`` called ``Table.empty_like``?<br><br>Cheers,<br>Tom<br><br><blockquote type="cite"><br>- Tom<br><br><blockquote type="cite"><br><br>In [3]: from astropy.table import Table<br><br>In [4]: t = Table([[1]])<br><br>In [5]: t2 = Table(t[0:0])<br><br>In [6]: t2<br>Out[6]:<br><Table masked=False length=0><br>col0<br>int64<br>-----<br><br>In [7]:<br><br>- Tom<br><br><blockquote type="cite"><br><br>Thank you,<br>Alexa<br>_______________________________________________<br>AstroPy mailing list<br><a href="mailto:AstroPy@scipy.org">AstroPy@scipy.org</a><br><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__mail.scipy.org_mailman_listinfo_astropy&d=AwIGaQ&c=-dg2m7zWuuDZ0MUcV7Sdqw&r=AHkQ8HPUDwzl0x62ybAnwN_OEebPRGDtcjUPBcnLYw4&m=tsHzQ6NpihEoX33pmnmiHF6nSNu86BozkIV4v_KCP6s&s=FRlFhyfQHtHEHMGpEAq6bnpkDKvPbatH7Q5WJ492XNU&e=">https://urldefense.proofpoint.com/v2/url?u=http-3A__mail.scipy.org_mailman_listinfo_astropy&d=AwIGaQ&c=-dg2m7zWuuDZ0MUcV7Sdqw&r=AHkQ8HPUDwzl0x62ybAnwN_OEebPRGDtcjUPBcnLYw4&m=tsHzQ6NpihEoX33pmnmiHF6nSNu86BozkIV4v_KCP6s&s=FRlFhyfQHtHEHMGpEAq6bnpkDKvPbatH7Q5WJ492XNU&e=</a><span class="Apple-converted-space"> </span><br></blockquote><br><br></blockquote><br><br>_______________________________________________<br>AstroPy mailing list<br><a href="mailto:AstroPy@scipy.org">AstroPy@scipy.org</a><br><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__mail.scipy.org_mailman_listinfo_astropy&d=AwIGaQ&c=-dg2m7zWuuDZ0MUcV7Sdqw&r=AHkQ8HPUDwzl0x62ybAnwN_OEebPRGDtcjUPBcnLYw4&m=tsHzQ6NpihEoX33pmnmiHF6nSNu86BozkIV4v_KCP6s&s=FRlFhyfQHtHEHMGpEAq6bnpkDKvPbatH7Q5WJ492XNU&e=">https://urldefense.proofpoint.com/v2/url?u=http-3A__mail.scipy.org_mailman_listinfo_astropy&d=AwIGaQ&c=-dg2m7zWuuDZ0MUcV7Sdqw&r=AHkQ8HPUDwzl0x62ybAnwN_OEebPRGDtcjUPBcnLYw4&m=tsHzQ6NpihEoX33pmnmiHF6nSNu86BozkIV4v_KCP6s&s=FRlFhyfQHtHEHMGpEAq6bnpkDKvPbatH7Q5WJ492XNU&e=</a><span class="Apple-converted-space"> </span><br><br></blockquote>_______________________________________________<br>AstroPy mailing list<br><a href="mailto:AstroPy@scipy.org">AstroPy@scipy.org</a><br><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__mail.scipy.org_mailman_listinfo_astropy&d=AwIGaQ&c=-dg2m7zWuuDZ0MUcV7Sdqw&r=AHkQ8HPUDwzl0x62ybAnwN_OEebPRGDtcjUPBcnLYw4&m=tsHzQ6NpihEoX33pmnmiHF6nSNu86BozkIV4v_KCP6s&s=FRlFhyfQHtHEHMGpEAq6bnpkDKvPbatH7Q5WJ492XNU&e=">https://urldefense.proofpoint.com/v2/url?u=http-3A__mail.scipy.org_mailman_listinfo_astropy&d=AwIGaQ&c=-dg2m7zWuuDZ0MUcV7Sdqw&r=AHkQ8HPUDwzl0x62ybAnwN_OEebPRGDtcjUPBcnLYw4&m=tsHzQ6NpihEoX33pmnmiHF6nSNu86BozkIV4v_KCP6s&s=FRlFhyfQHtHEHMGpEAq6bnpkDKvPbatH7Q5WJ492XNU&e=</a></div></blockquote></div><br></div></body></html>