Repository navigation
Use quantity to value - #6137
Conversation
| ``to_value(unit)`` method, since this is somewhat faster. Any subclasses | ||
| that overwrote ``.to``, should also overwrite ``.tovalue`` (or | ||
| possibly just the priviate ``._to_value`` method. (If you did this, | ||
| please let us know what was lacking that made this necessary!). [#6136] |
There was a problem hiding this comment.
typos: tovalue → to_value, priviate → private
There was a problem hiding this comment.
Thanks! Since travis and appveyor hadn't even started yet, I cancelled those builds and fixed this immediately
6abb25a to
fde260c
Compare
taldcroft
left a comment
There was a problem hiding this comment.
A couple of questions, otherwise looks good to me.
|
|
||
| - Internally, astropy replaced use of ``.to(unit).value`` with the new | ||
| ``to_value(unit)`` method, since this is somewhat faster. Any subclasses | ||
| that overwrote ``.to``, should also overwrite ``.tovalue`` (or |
| raise ValueError("Size Error: Arrays will be {}. Use " | ||
| "allow_huge=True to override this exception." | ||
| .format(human_file_size(array_size_C.to(u.byte).value))) | ||
| .format(human_file_size(array_size_C))) |
There was a problem hiding this comment.
Yes, human_file_size understands Quantity, so no need to convert here. I think this was just missed when human_file_size was changed.
| # Possibly scaled unit any quantity-likes should be converted to | ||
| _unit = u.CompositeUnit(getattr(self, 'unit', 1.), [u.day], [1]) | ||
| val1 = val1.to(_unit).value | ||
| val1 = u.Quantity(val1, copy=False).to_value(_unit) |
There was a problem hiding this comment.
I'm sure there is a reason, but why did you change in this way?
There was a problem hiding this comment.
At first, I just changed to to_value, but this failed, since one of the tests uses Column (which has a to method, but not a to_value). When I noticed that, I felt it was actually better not to assume having a unit goes with having to method either, but rather just let the Quantity initializer deal with different objects that have a .unit attribute.
There was a problem hiding this comment.
OK, now I understand. I've never liked duck-typing by attribute names.
|
Question -- there was one tested instance where a both a |
| val = self._match_shape(val) | ||
| if hasattr(val, 'to'): # Matches Quantity but also TimeDelta. | ||
| val = val.to(u.second).value | ||
| val = val.to_value(u.second) |
There was a problem hiding this comment.
Good call on checking for other classes. This one is wrong (and the other setter too). Will correct.
|
Yes, good point. I went through the whole list again, and did find two instances where I should not have changed it: in the setters for |
|
p.s. The other changes are all in places where it is known that we're dealing with a |
aeead99 to
acdfd67
Compare
|
I think this is ready to go in -- tests pass now. Any objections? |
|
So my only outstanding question is whether we give In essence allow astropy and other developers to write code that treats This would allow undoing 167082e etc., and in some sense then the tests would already be written. 😄 |
|
@mhvk - do you plan to wrap this up for 2.0? |
|
I don't think that the issue of a So, I'm 👍 on merge (of course rebase is needed). |
acdfd67 to
6730efa
Compare
|
I was indeed not planning to add anything to here; we can decide later whether it is useful for Anyway, now rebased. |
| assert '...' in bigarrangle._repr_latex_() | ||
|
|
||
|
|
||
| def test_rotation_matrix_deprecation(): |
There was a problem hiding this comment.
Ah, duh, that was a conflict and I did the wrong thing. Will fix...
There was a problem hiding this comment.
No worries. I see thumbs up above, if this is good to go once given the all green by CI, please add the merge-when-ci-passes label.
|
Cancelling travis and appveyor as this has genuine failures, see comment and the CircleCI log. |
6730efa to
d34e9f3
Compare
|
@bsipocz - thanks for merging this! However, I noticed the following issue with this pull request:
Would it be possible to fix this? Thanks! If you believe the above to be incorrect (which I - @astrobot - very much doubt) you can ping @astrofrog |
|
Just for the record, change log is there but not this PR number. |
| ``to_value(unit)`` method, since this is somewhat faster. Any subclasses | ||
| that overwrote ``.to``, should also overwrite ``.to_value`` (or | ||
| possibly just the private ``._to_value`` method. (If you did this, | ||
| please let us know what was lacking that made this necessary!). [#6136] |
There was a problem hiding this comment.
Typo in PR number that astrobot noted. I'll fix it before release.
There was a problem hiding this comment.
It is actually the issue number this PR fixes, so not strictly a typo. 😄
There was a problem hiding this comment.
Then the issue is the missing PR number. Neither the bot, nor the release script care about issue numbers, but about the PR numbers :)
There was a problem hiding this comment.
Sorry to have missed that...
|
This did break some code of mine where I called I realise that |
fix #6136