<div dir="ltr">If anyone is interested in continuing the discussion on github, see:<div><br></div><div><a href="https://github.com/astropy/astropy/issues/3742">https://github.com/astropy/astropy/issues/3742</a><br></div><div><br></div><div>- Tom</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Apr 29, 2015 at 2:57 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thank you, everyone, for your helpful responses.<br>
<br>
If it’s of any interest, I ended up going with Tom A.’s solution because one of my columns holds arrays instead of single values. The dtype entry for that looks like ‘(‘SPEC’, ‘>f4’, (7925,)’ which was fully copied in Tom A.’s solution but not Tom R.’s.<br>
<br>
Best,<br>
Alexa<br>
<div><div class="h5"><br>
On Apr 29, 2015, at 11:45 AM, Andrew Hearin <<a href="mailto:andrew.hearin@yale.edu">andrew.hearin@yale.edu</a>> wrote:<br>
<br>
> 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.<br>
><br>
><br>
> On Apr 29, 2015, at 2:21 PM, Thomas Robitaille <<a href="mailto:thomas.robitaille@gmail.com">thomas.robitaille@gmail.com</a>> wrote:<br>
><br>
>> 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>
>>><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>
>>>><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>
>>>>><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>
>>>><br>
>>>><br>
>>>> You should be able to do:<br>
>>>><br>
>>>>>>> irtf_hb = Table(irtf[0:0])<br>
>>>><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>
>>><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>
>><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>
>>><br>
>>> - Tom<br>
>>><br>
>>>><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>
>>>>><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=" target="_blank">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><br>
>>>><br>
>>>><br>
>>><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=" target="_blank">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><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=" target="_blank">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><br>
><br>
> _______________________________________________<br>
> AstroPy mailing list<br>
> <a href="mailto:AstroPy@scipy.org">AstroPy@scipy.org</a><br>
</div></div>> <a href="http://mail.scipy.org/mailman/listinfo/astropy" target="_blank">http://mail.scipy.org/mailman/listinfo/astropy</a><br>
<span class=""><br>
_______________________________________________<br>
AstroPy mailing list<br>
<a href="mailto:AstroPy@scipy.org">AstroPy@scipy.org</a><br>
</span><a href="http://mail.scipy.org/mailman/listinfo/astropy" target="_blank">http://mail.scipy.org/mailman/listinfo/astropy</a><br>
</blockquote></div><br></div>