[AstroPy] Vector Quantities in QTable

Aldcroft, Thomas aldcroft at head.cfa.harvard.edu
Mon May 15 14:18:23 EDT 2017


Hi Jeffrey,

Sorry for the delay, I finally had a chance to dig into this.

Congratulations, you have found a real bug (
https://github.com/astropy/astropy/issues/6072).  There is no bounty but we
should be able to fix this for next bug-fix release.  Unfortunately I can't
think of an easy workaround apart from assembling the table as a Table and
then converting to QTable at the end.

>>> foo = Table(names=('state1','mass'),dtype=('(3,)f8','f8'))
>>> foo['state1'].unit = u.K
>>> foo['mass'].unit = u.mg
>>> s0 = [235,240,245]*u.K
>>> m0 = 5*u.g
>>> foo.add_row((s0.to(u.K), m0.to(u.mg)))
>>> foo = QTable(foo, copy=False)
>>> foo
<QTable length=1>
  state1 [3]     mass
      K           mg
   float64     float64
-------------- -------
235.0 .. 245.0  5000.0

Cheers,
Tom

On Thu, Apr 13, 2017 at 4:29 PM, Jeffrey Brent McBeth <mcbeth at broggs.org>
wrote:

> On Thu, Apr 13, 2017 at 11:25:39AM -0700, Michael Walther wrote:
> > Hi Jeffrey,
> >
> > Exchange:
> > foo = QTable(names=('state1','mass'),dtype=('(3,1)f8','f8'))
> > by:
> > foo = QTable(names=('state1','mass'),dtype=('(3,)f8','f8'))
> >
> > Then it works (at least for this simplified case).
>
> I'm sorry, I cannot reproduce the code working with your substitution.
> Both forms work fine (3,1), (3,) if I do not specify the units of the
> column
> Well, I say fine, except the units are stripped off the data and are not
> preserved in the QTable
>
> If I have the unit definitions before trying to add a row, then I'm back
> to where I was.
>
> I have astropy 1.3.2 and I've tried on python 2.7.12 and 3.5.2.
>
> Thanks,
>  Jeffrey
> --
> "The man who does not read good books has no advantage over
>  the man who cannot read them."
>  -- not Mark Twain, maybe a southen librarian in 1910
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20170515/2a815b83/attachment.html>


More information about the AstroPy mailing list