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
Cosmological units module #12092
Cosmological units module #12092
Conversation
Hello @nstarman 👋! It looks like you've made some changes in your pull request, so I've checked the code again for style. There are no PEP8 style issues with this pull request - thanks! 🎉 Comment last updated at 2021-08-24 19:33:17 UTC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good. A question is whether the documentation of with_H0
in units.equivalencies
should not just point here. But perhaps that becomes more logical if the equivalency and unit definitions are moved here as well - which is perhaps requires more logic than is worth it...
Anyway, more important is to move forward and define new stuff here!
docs/cosmology/index.rst
Outdated
@@ -557,3 +566,4 @@ Reference/API | |||
============= | |||
|
|||
.. automodapi:: astropy.cosmology | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extraneous empty line? (Emacs would auto-remove it with my no-end-of-line space setting...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah. My editor has an end-of-line space setting! 😆.
I think it's PEP8 W292 (https://www.flake8rules.com/rules/W292.html)
astropy/cosmology/units.py
Outdated
# This generates a docstring for this module that describes all of the | ||
# standard units defined here. | ||
if __doc__ is not None: | ||
__doc__ += _generate_unit_summary(globals()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be an idea to define enable()
(as in imperial.py
, etc.)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me take a look! that seems a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My second thought was perhaps not (see below), but do have your own look, since clearly I am wavering!
bf9af7a
to
3a44376
Compare
@mhvk, I'm not sure if we want to deprecate |
docs/cosmology/units.rst
Outdated
"hours." | ||
|
||
If no argument is given (or the argument is `None`), this equivalency assumes | ||
the ``H0`` from the current default :ref:`cosmology <astropy-cosmology>`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When this text was in the units documentation it made sense to have a link to the cosmology subpackage, but if you are moving the text then it might be better to use
the ``H0`` from the current default :ref:`cosmology <astropy-cosmology>`: | |
the ``H0`` from the current default :class:`~astropy.cosmology.Cosmology`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! applied in 958aa5c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was unsure, but now seeing it, I think a real move to cosmology.units
and deprecating in units
is the right way to go! Also, LTS versions are the best place to do these types of things, as then they have more minimal impact for packages that try to support LTS+current.
@@ -0,0 +1,3 @@ | |||
Added units module for defining and collecting cosmological units and | |||
equivalencies. The units can be added to the main Astropy units namespace using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you noted, this is not quite true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed that portion.
For some future date: with a module-level__getattr__
and the units registry it should be possible for add_enabled_units
to also put the units on the top-level namespace in a way that's compatible with _UnitsContext
(context manager returned by add_enabled_units
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, though perhaps too much magic? And perhaps worries for thread safety? I guess the idea of enabling units was mostly that they can be used in strings, and thus in storing them inside files, etc.
588c0bf
to
f3f3c00
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks all great now, except still to revert the added lines in docs/units/index.rst
(I think).
docs/units/index.rst
Outdated
@@ -252,6 +253,7 @@ Reference/API | |||
.. automodapi:: astropy.units.physical | |||
|
|||
.. automodapi:: astropy.units.equivalencies | |||
:skip: with_H0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this one too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did those sneak in there?!? I used a fixup!
commit to prune them from the whole history
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gone now.
Signed-off-by: Nathaniel Starkman (@nstarman) <nstarkman@protonmail.com>
Thanks @mhvk and @eerovaher for the reviews! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks all OK now! (Weird about the git thingy not working)
The code coverage is clearly a red herring, so merging. Thanks, @nstarman! |
@mhvk. I'm thinking this might have merited a whatsnew... here or in the followup adding cosmological redshift units |
Yes, with the redshift unit - so that it makes sense that there is a new cosmology.units module. |
In astropy#12092 `littleh` and `with_H0` were moved from `units` to `cosmology.units`, but importing them from `units` was still possible, albeit deprecated. Removing them from `units` entirely finalizes the moving process.
Adds a new module to Cosmology —
units
— for defining and collecting cosmological units andequivalencies.
@eteq, though I advocated for it, I'm holding off from actually moving
littleh
andwith_H0
for now. The latter will be easy to move, but movinglittleh
and having it be imported intounits/astrophys
is a nightmare of circular imports.It would be much easier to just deprecate it from
units/astrophys
, but I'd want some discussion on that, and since it's a low priority, I'll save it for a followup. Thanks!Necessary For : #11784
Fixes: #12093
Checklist for package maintainer(s)
This checklist is meant to remind the package maintainer(s) who will review this pull request of some common things to look for. This list is not exhaustive.
Extra CI
label.no-changelog-entry-needed
label.astropy-bot
check might be missing; do not let the green checkmark fool you.backport-X.Y.x
label(s) before merge.