Skip to content

Conversation

@mhvk
Copy link
Contributor

@mhvk mhvk commented Oct 8, 2013

This follows a question from @taldcroft in #732 whether one could set a Quantity with a table column. With this:

from astropy.table import Table; import astropy.units as u
t = Table([[1.,2.],[3.,4.]], names=('a','b'))
t['a'].unit = u.km
u.Quantity(t['a']), u.Quantity(t['a'], u.m), u.Quantity(t['b']), u.Quantity(t['b'], u.Mpc/u.m)

yields

(<Quantity [ 1., 2.] km>,
 <Quantity [ 1000., 2000.] m>,
 <Quantity [ 3., 4.] >,
 <Quantity [ 3., 4.] Mpc / m>)

Hence, an unset unit is taken as "treat this as a float array" rather than dimensionless unscaled.

Notes:

  1. This trial implementation goes the route of making quantity initialisation duck type; instead of looking whether one is dealing with a Quantity instance, it looks whether there is an unit attribute; the one extra part required was for Column to have a value attribute (just equal to data).
  2. Miraculously, it doesn't break any test cases!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this a property like data so it is strictly read only.

@astrofrog
Copy link
Member

@mhvk - could you rebase, and add tests?

@mhvk
Copy link
Contributor Author

mhvk commented Nov 26, 2013

@astrofrog - I'm not quite sure any more this is the right approach towards solving the general problem of interacting with Quantity, Time, and Coordinates. I've been working with @wkerzendorf on an alternative and think it would be best to hold off on this PR until that has been explored a bit further (especially since this PR affects Quantity and there still a few others for Quantity that have higher priority).

@taldcroft
Copy link
Member

@mhvk @astrofrog - I agree this is likely to be overtaken by approaches suggested in #1833 and #1835. We should leave this PR open though. For instance there may end up being a table attribute like use_quantity which might be set to false. In this case the approach use in this PR would still be appropriate.

@astrofrog astrofrog modified the milestones: v1.0.0, v0.4.0 May 3, 2014
@eteq
Copy link
Member

eteq commented Jul 6, 2014

@mhvk - this has been overtaken by some later PR, right? In master, right now, it appears your example at the top works. So should this be closed?

@mhvk
Copy link
Contributor Author

mhvk commented Jul 6, 2014

@eteq - yes, indeed Quantity now duck types right, so no need for this any more. I'll close it.

@mhvk mhvk closed this Jul 6, 2014
@mhvk mhvk deleted the quantity-input-from-column branch July 6, 2014 10:19
@embray embray removed this from the v1.0.0 milestone Jul 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants