Skip to content

Make tables work consistently with quantites #2000

@eteq

Description

@eteq

I noticed some odd behavior while working with astropy.table.Tables loaded with ascii, that I've tried to capture here:

First, just create a table with columns that have a unit:

>>> t=table.Table()
>>> t.add_column(table.Column(name='length',unit=u.km,data=randn(10)))
>>> t.add_column(table.Column(name='time',unit=u.s,data=randn(10)))

Now, lets say I want to make a velocity:

>>> v = t['length']/t['time']
>>> v
<Column name='length' unit=u'km' format=None description=None>
...

That on its own is a bit weird, because it grabs one of the names and units despite it being an operation on the two columns. But that I can accept on its own - the really weirdness is here:

>>> t['length']*u.km/ (t['time']*u.second)
<Quantity [ .. ] km2 / s2> # this *includes* the column's unit
>>> u.Quantity(t['length'])/u.Quantity(t['time'])
<Quantity [  ... ] > # no unit *at all*

So is this intended behavior, a bug, or none of the above? I think my preferred behavior would be for operations on two columns to yield a Quantity instead of a Column.

cc @taldcroft @astrofrog

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions