Repository navigation
Units equivalency context manager -- mostly for dimensionless angles - #1593
Conversation
There was a problem hiding this comment.
This will also reset the enabled units. I think we only want to set self._equivalencies = set() here. Likewise set_enabled_units will reset the enabled equivalencies. These should be independent.
|
@mdboom - I do think it is important to be able to turn off the context temporarily (and this is needed in |
|
@mdboom - OK, I changed In addition, I thought I should really pre-normalize equivalencies in the registry -- which was a bit of a can of worms, since |
There was a problem hiding this comment.
This looks good, but I think it also makes sense to document the set_enabled_equivalencies functions at the top level of this file. It one wanted to do it for another equivalency than this one, it might be hard to find it here.
|
Apart from my documentation comment, I think this is looking quite good. |
|
@mdboom - yes, indeed, much better -- especially if equivalency moves out of quantity, this will be much more generally useful. Now done (plus some clean-up of that page; sorry if that makes it quite a bit less easy to check). |
|
That doc looks much better. I think this is in good shape, and as you say, makes the removal of equivalencies from Quantity feasible, since there's something good to replace it with. |
|
@mdboom - OK, thanks! (and spelling corrected). |
There was a problem hiding this comment.
I think this is causing the Travis tests to fail. Since this is an external reference, I think it needs to look like:
`supplementary to derived unit <http://www.bipm.org/en/CGPM/db/20/8/>`__
Likewise for the other links below.
|
@mdboom, @astrofrog - the travis sphinx failure would seem to be related to modelling rather than this PR. Perhaps a problem with a random number? I thought I'd pass it on rather than uploading a no-op change to get it to rebuild. |
|
@mhvk: At this point, this needs a rebase anyway. Would you mind doing that? That should also trigger a rebuild of Travis... |
|
@astrofrog, @mdboom - I rebased and pushed but Travis doesn't seem to start. Any idea? Note: somewhat sillily, I rebased this one rather than #1161; do you want to consider both together here? I'm not sure how to get #1161 in order without redoing the edits. |
|
@mhvk - I think Travis was just under heavy load. I restarted the build manually. |
|
Finally managed to get the context manager documentation bug-free as well. @mdboom: would you consider this to be ready to go in? |
There was a problem hiding this comment.
Maybe that helps convert between angles and dimensionless units? Otherwise the sentence feels a bit incomplete.
|
This looks really good and ready to merge, aside from the very minor comments. However... we're working on top of each other a bit today. I just filed #1662 which simplifies the use of the context manager and combines |
Also rename equivalency to angles_dimensionless
|
@mdboom - OK, it was not bad at all -- I do like the new way of doing it, much cleaner! Note that I took the liberty of adding some comments also to your |
There was a problem hiding this comment.
equivalencies=equivalencies ?
|
We're getting this doc error: Other than that, I think this is good to go, and thanks for handling the 11th hour update to the less complicated context managers. |
|
@mdboom - p.s. you comment on the wrong initialisation in the |
|
@mhvk - it looks like this needs rebasing? |
|
@astrofrog - hmm, odd, maybe because of #1634? (actually, how does one see whether it needs rebasing?) Since #1161 and #1662 may also suffer from this, perhaps it is best for me to wait until those are in, and then rebase. |
|
@mhvk - if it says "We can’t automatically merge this pull request." it means you need to rebase. Sometimes it's something as simple as a CHANGE.rst addition conflicting. |
|
@astrofrog - I don't see that -- but checking on my own repository, I do see it there, so I guess this is simply hidden from people who do not have merge rights. I guess the way around it is to simply try it locally, a la Oddly enough, though, that actually works... Anyway, as said, #1161 and #1662 should really go in first (unless you want to do it in one fell swoop). Since apparently I cannot test this locally, is #1161 OK? |
|
Oh that's annoying (only committers can see the message). |
|
Merged (manually). |
This is a follow-up on #1161, which introduced an equivalency that allows radian to be dimensionless. That PR still required the equivalency to be explicitly given, which does not address all uses (in particular, the example below). The present PR adds
equivalenciesto theUnitRegistryclass, and with that the ability to set an equivalency context. E.g.,yields
@mdboom: one change beyond introducing, testing, and documenting this, is that the default for
equivalenciesfor all user-facing methods is changed toNone, so that[]can be used to override any global equivalencies in effect.