[AstroPy] append problem in atpy

Frederic Grollier fred.grollier at gmail.com
Fri Apr 8 04:42:12 EDT 2011


I don't know much atpy, but as far as I can tell your problem lies in the fact
that you're trying to stack two numpy structured arrays with mismatching
dtypes ; at the end of your example, t.data.dtype is :

[('num', '<i4'), 'name', '|S3')]

while p's one is

[('name', '|S3'), ('num', '<i4')]

 so you can't stack them easily.

You should use the 'before' keyword of add_column
(t.add_column("name", nn, before="num")) so that your array types stay
consistent (and appendable)

Cheers,
Frederic.



On Thu, Apr 07, 2011 at 03:47:38PM -0400, Tommy Grav wrote:
> I am a big fan on atpy and use it extensively in reading IPAC/IRSA tables. However I get this error 
> when trying to append two tables with strings that I do not understand. Does anyone know what is happening
> and how to get around it
> 
> >>> import atpy
> >>> t = atpy.Table()
> >>> name = ["aa","bb","cc"]
> >>> t.add_column("name",name)
> >>> k = [1,2,3]
> >>> t.add_column("num",k)
> >>> t
> <Table name='None' rows=3 fields=2>
> >>> name = ["aaa","bbb","ccc"]
> >>> p = atpy.Table()
> >>> p.add_column("name",name)
> >>> p.add_column("num",k)
> >>> t.append(p)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/atpy/basetable.py", line 301, in append
>   raise Exception("Columns do not match")
> Exception: Columns do not match
> >>> nn = t.name.astype("|S3")
> >>> t.remove_columns("name")
> >>> t.add_column("name",nn)
> >>> t.append(p)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/atpy/basetable.py", line 302, in append
>   self.data = np.hstack((self.data, table.data))
> File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/shape_base.py", line 258, in hstack
>   return _nx.concatenate(map(atleast_1d,tup),1)
> TypeError: expected a readable buffer object
> >>> 
> 
> Cheers
>  Tommy




More information about the AstroPy mailing list