Skip to content

CompositeUnit has no value attribute - #1610

Merged
mdboom merged 1 commit into
astropy:masterfrom
mdboom:unit/cgs_si_properties
Oct 22, 2013
Merged

mdboom merged 1 commit into
astropy:masterfrom
mdboom:unit/cgs_si_properties

Conversation

@mdboom

@mdboom mdboom commented Oct 21, 2013

Copy link
Copy Markdown
Contributor

This may be more of a user bug than anything else, is there a reason why CompositeUnit dosen't have the same API as Unit and have a value attribute?

@mhvk

mhvk commented Oct 19, 2013

Copy link
Copy Markdown
Contributor

@Cadair - this is true for all units -- they do have a scale but no value. As something similar came up before, why specifically do you ask? Maybe there is a usage that we are not supporting yet, but should? Or where we should point more clearly to the "right" way?

@Cadair

Cadair commented Oct 19, 2013

Copy link
Copy Markdown
Member Author

Ah ok it's Quantity that has the value attribute, which makes more sense. So what I was trying to do was this:

>>> u.m.to_system(u.cgs)[0]
Unit("100 cm")

How do I extract the 100?!

@mhvk

mhvk commented Oct 19, 2013

Copy link
Copy Markdown
Contributor

That would be .scale, i.e.,

>>> u.m.to_system(u.cgs)[0].scale

I'd actually naively have tried to do u.m.cgs by analogy of what I do with quantities, (1*u.m).cgs, but that does not work. While I can see the reason for not wanting to have a value, the absence of a cgs property seems a bit odd -- cc: @mdboom.

@mdboom

mdboom commented Oct 21, 2013

Copy link
Copy Markdown
Contributor

Yeah -- we could add the cgs and si convenience properties. to_system is obviously more powerful and general, but if Quantity has them, Unit should probably have them to. I'll work up a pull request for this.

@mdboom

mdboom commented Oct 21, 2013

Copy link
Copy Markdown
Contributor

And just a little history on this: I've never been much of a fan of Quantity.cgs and Quantity.si, since it's possible for there to be multiple correct recompositions, and we don't (currently) specify which are more idiomatic. However, people have been using it and the sky has not fallen...

@mdboom

mdboom commented Oct 21, 2013

Copy link
Copy Markdown
Contributor

Fix attached.

@mhvk

mhvk commented Oct 21, 2013

Copy link
Copy Markdown
Contributor

Nice! And also seems a bit cleaner to have this in unit rather than in quantity -- which should know as little about the units as possible.

I looked through the changes in some detail and it all looks good to me.

mdboom added a commit that referenced this pull request Oct 22, 2013
CompositeUnit has no value attribute
@mdboom
mdboom merged commit e11f3de into astropy:master Oct 22, 2013
@mdboom
mdboom deleted the unit/cgs_si_properties branch May 21, 2014 23:57
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.

3 participants