-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Set column units when initializing Column or Table from a Quantity #732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set column units when initializing Column or Table from a Quantity #732
Conversation
|
👍 , as this addresses one of the main reasons in my head for #729 |
|
I think this could easily be done already - even if we don't do everything done in #664, just this would already be useful. With the new API, we could even do: and the unit would get auto-set. Note, we don't have to yet decide whether accessing a column returns a Quantity, but at least for now the above behavior should be unambiguous. |
|
@taldcroft @eteq - I attached code that does this, but we should discuss the behavior a little more. With this patch: Note that if the Now this should be made consistent with whatever |
|
@astrofrog - I think this looks very good! And it seems logical to make the behaviour the same as for But why is one test commented out? |
|
@mhvk - oops, fixed now :) |
|
@taldcroft - can you review this? (and merge if happy with it?) |
|
@astrofrog - OK will look at this. |
|
The code and tests look good. Seems like it would be worth putting in an example in the sphinx Table docs. It's a cool feature that might not be obvious to people. |
|
@astrofrog @mdboom @mhvk - slightly OT, but we've been talking about Table columns and Quantity. I wonder if we could do something easy in the short term and allow a Table column with units to initialize a Quantity: One might also do [EDIT: I didn't check if this already works...] |
|
@taldcroft - no, this did not yet work, but should. Just make a sample implementation... @astrofrog - while making that sample implementation, I went the duck-type route and I wondered whether one shouldn't do the same here. I.e., check whether the input has a |
|
@taldcroft - it this looks ok, and Travis passes, shall I merge this? (I added some documentation and an entry in |
|
@mhvk - I'm not too comfortable with the duck-typing, hence why I left it as-is. But if other people also agree duck-typing is the way to go then we can do that. |
|
@astrofrog - no problem, I think this is not particularly important for this issue. But once the integration of the packages becomes tighter, it will become useful to think that defining characteristics each have, and work with those rather than |
Set column units when initializing Column or Table from a Quantity
|
@astrofrog - looks great, I went ahead and merged it. |
|
Thanks @astrofrog and @taldcroft - with this I think my original complaint from way back in #729 is resolved, and now I have no right to ever again complain about creating columns! :) |
Column('a', np.arange(3) * u.mshould initialize the columnunitsattribute tou.m. Currently the unit is just dropped on the floor.This will apply to all
Tableoperations as well.