Skip to content

Add a new to_value method to Quantity. - #6127

Merged
adrn merged 3 commits into
astropy:masterfrom
mhvk:quantity-to-value
May 30, 2017
Merged

adrn merged 3 commits into
astropy:masterfrom
mhvk:quantity-to-value

Conversation

@mhvk

@mhvk mhvk commented May 29, 2017

Copy link
Copy Markdown
Contributor

This returns the value of the quantity in the given unit.

@taldcroft: I ended up with to_value as I felt it was a bit more uniform (with to_string, etc.) and makes more sense without arguments (a form that needs to exist to make the property work, i.e., q.to_value() is obvious but q.value_in() is not). I also ended up not using it for to, as especially the scalar case is slowed down a little too much by first doing value.item() and then recreating an array in _new_view.

Fixes #6125

This returns the value of the quantity in the given unit.
@mhvk mhvk added Affects-dev PRs and issues that do not impact an existing Astropy release units labels May 29, 2017
@mhvk mhvk added this to the v2.0.0 milestone May 29, 2017
@mhvk
mhvk requested review from adrn and taldcroft May 29, 2017 16:00

@taldcroft taldcroft left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me!

@taldcroft

Copy link
Copy Markdown
Member

Doc and remote test fails appear unrelated.

@taldcroft

Copy link
Copy Markdown
Member

Why is this marked Affects Dev? I thought that was mostly reserved for something like a bug fix or change that only affects dev. I.e. it would not even make sense to apply to the last release and often doesn't need a changelog.

@mhvk
mhvk force-pushed the quantity-to-value branch from b5bb76f to 3ac46db Compare May 29, 2017 19:58
@mhvk mhvk added Affects-release and removed Affects-dev PRs and issues that do not impact an existing Astropy release labels May 29, 2017
@mhvk

mhvk commented May 29, 2017

Copy link
Copy Markdown
Contributor Author

I've never understood affects-* too well...

Sadly, the documentation failure was real, but it made me realize I should ensure this works for EarthLocation as well, so it was good in that sense.

@bsipocz

bsipocz commented May 29, 2017

Copy link
Copy Markdown
Member

@mhvk - Basically both Affects-* labels are most useful to bugfixes (and bug reporting issues) and the sole purpose is to notify the person (and the script) whether that given bug was existed in a released version. If it was then it most probably needs to be backported, if not it will need to be on master only, and most probably won't need a changelog entry.

The other usecase for Affects-dev could be that it's an enhancement on a new feature in master, thus no changelog will be needed as the feature already has its entry.

@adrn adrn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks fine to me, though I'm somewhat neutral on the concept of the addition. On one hand, we now have two ways to effectively do the same thing with a difference of just a few characters. On the other hand, I do find myself typing .to(...).value quite often in my own code!

One open question I'm pondering is whether we want to take a stance and explicitly recommend using to_value() over to(...).value. If so, we should replace any instances of the latter in the documentation with the new method.

@mhvk

mhvk commented May 30, 2017

Copy link
Copy Markdown
Contributor Author

@adrn - to_value is faster (no needless creation of a new Quantity only to discard it immediately), so, yes, we should recommend that. A quick grep shows only two instances in the documentation, but quite a lot of instances in the code...

@adrn

adrn commented May 30, 2017

Copy link
Copy Markdown
Member

@mhvk Hm, yea, I see 205 matches with to\(.+\)\.value -- how do you think we should handle replacing those?

@taldcroft

Copy link
Copy Markdown
Member

@bsipocz

bsipocz commented May 30, 2017

Copy link
Copy Markdown
Member

👍 to do the replaces separately (btw I would do it with sed, but I believe perl can do this, too).

@saimn

saimn commented May 30, 2017

Copy link
Copy Markdown
Contributor

Excellent news if this is faster !

@adrn

adrn commented May 30, 2017

Copy link
Copy Markdown
Member

OK sounds good. I've created an issue just so we don't forget. Tests are passing and doubly-approved, so merging now.

@adrn
adrn merged commit 65fea6f into astropy:master May 30, 2017
@bsipocz

bsipocz commented May 30, 2017

Copy link
Copy Markdown
Member

Would the performance enhancement resulted from this deserve a what's new entry? Maybe one entry that includes all the performance enhancements made in v2.0?

@mhvk

mhvk commented May 30, 2017

Copy link
Copy Markdown
Contributor Author

In principle, yes, but I think that would at the minimum involve getting asv working again, so we can quantify what the improvement actually is!

@bsipocz

bsipocz commented May 30, 2017

Copy link
Copy Markdown
Member

Running it on a CI is really not an option? I expect the general trends to show up there even on travis, and maybe circle or appveyor would work better?

@mhvk mhvk mentioned this pull request May 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants