Repository navigation
Remove prefixes for jupiter/earth/sun masses - #5661
Conversation
|
👍 I didn't add the prefixes intentionally, I just c&p'd the |
|
But several people already used them, I dimly remember some issues about |
|
I agree the prefixes should not be used; we also do not have them on proton mass, etc. (although we do have them on the unified atomic mass unit |
|
👍 to remove these, and doing the same for the radii too. |
|
I agree these prefixed units should be removed, but share other concerns about breaking existing code. On the other hand, I'm not sure we currently have a way to deprecate units? |
|
Indeed, I can't think of an easy way to deprecate just a prefix of a unit for only some units. How about we just straight out remove this for 2.0 release? It is a major version change anyway, so people should expect some non-backward compatible stuff. |
@MSeifert04 - do you remember who/what this was from? |
|
Also, I'm noticing the failures all seem to be due to VO units. Does anyone understand why these are there? It appears the tests are making sure that all of the prefix are present for all of the "solar" units. I could see this as an argument for keeping the solar units, but I guess I'm lost as to whether or not VO actually expects this somewhere...? (Maybe @pllim or @astrfrog know?) Alternatively, maybe the prefixes should be valid units, but not have them be in the |
@eteq I can only find #5517. Sorry, I thought I already posted it. |
|
after re-reading that issue: It was an example where it confused someone, so maybe that issue is in favor of removing them? 😄 |
|
Looking at IVOA recommendations v1.0 for VO units, in Table 2, unfortunately, "solar mass" is allowed to have prefix ("s") under "vou" column. Is that something that Astropy supports? |
|
If the IVOA allows prefixes, we should do the same for our VO units (i.e., at least for Msun). Since these are defined separately, in principle this PR should not affect that, but I think that so far the assumption has been that our "generic" units are a superset of all of fits, ogip, and vo (but not of cds, which, therefore, can be used as a units context, unlike the others). So, perhaps the simplest solution is to keep the prefixes for solar units, but remove them for earth and jupiter mass/radius? |
But the original confusion in #5517 was about solar mass in the first place... |
Agreed, but there is something to be said for including all allowed fits, ogip and vo units by default, i.e., staying close to some standard even if we don't quite like it (and I definitely do not like prefixes on solar units...). |
Can you clarify what you mean by that? It looks to me like they are not defined separately, and that's why this is failing. Can we maybe have our cake and eat it too, though, by not having the prefixed units in the default namespace, but still having them be defined as units? Then |
|
It may be possible to disentangle what is in the namespace from what is in the unit registry, but I'm not completely sure we would want that. As for my "in principle": this referred to the fact that vo and generic could be disentangled, but that so far the assumption, also in our tests, has been that generic is a superset that includes all vo units. I think (but have not tried) that if you just removed the earth and jupiter mass prefixes, all tests should pass. (which is why my tendency would be to do at least that, and worry about solar mass separately). |
|
@eteq - I think we're a bit stuck on the solar mass here, which would require more drastic surgery to get to work. How about at least removing the prefixes for earth and jupiter mass here? |
|
@eteq , there is a |
|
Thanks for the reviews, @pllim and @mhvk - I think I've implemented the changes. @mhvk - that's right - there's actually no deprecation warning for using this - they just have to be pulled in explicitly by However, I realize I was having a misunderstanding: I thought having them in the I think the best work-around is to add another unit set just like deprecated, but that is by default enabled. The commits I just put up do that. Note that I also had to tweak the unit-table-generating docstring machinery to do something useful for this use case. You can check out the end result at http://eteq.github.io/astropy/units/index.html#module-astropy.units.vounit_needed. (Note that this has changed enough that @pllim and/or @mhvk might want to do a re-review...) |
|
|
||
| - ``solLum``,``solMass``, and ``solRad`` no longer have their prefixed units | ||
| included in the standard units. If needed, they can still be found in | ||
| ``units.vounit_needed``, and are enabled by default. [#5661] |
There was a problem hiding this comment.
"vounit_needed" sounds very cryptic. Needed for what? "vounit_with_prefix"? "vounit_that_eteq_hates_but_cannot_deprecate"? 😉
There was a problem hiding this comment.
I think the fully descriptive name would be required_by_the_vounit_standard_but_not_actually_ever_used_by_an_astronomer_in_real_life_so_would_be_confusing_to_have_in_the_main_namespace. But that's 141 characters, which is > 80 😉.
Maybe required_for_vounit? Or prefixed_vounits?
There was a problem hiding this comment.
I'll try going with required_by_vounit . I favor that over vounit_with_prefix only because it's possible that in the future we might put non-prefix units there (if there's ever a VOUnit 2.0 or another change in what people think should be in astropy.units).
There was a problem hiding this comment.
@eteq , these are not the only units in VO standards though. Naming these "required by VO" implies others are not required, unless you want to put all VO units here. It's a can 'o worms.
There was a problem hiding this comment.
Hmm, I see that. It's really required_by_vounit_buy_not_in_units, but that's still awkwardly long.
| # This generates a docstring for this module that describes all of the | ||
| # standard units defined here. | ||
| from .utils import generate_unit_summary as _generate_unit_summary # noqa | ||
| from .utils import generate_prefixonly_unit_summary as _generate_prefixonly_unit_summary # noqa |
There was a problem hiding this comment.
Just following what that module is already doing. I know some of this stuff is full of circular-import landmines, so I'm guessing that's the reason? And it's not really performance-sensitive so it only gets run once at import-time, practically speaking.
There was a problem hiding this comment.
This is imported but not used, so unnecessary for this module? Unless you forgot to call it below?
There was a problem hiding this comment.
oops! Good catch - it is indeed supposed to be called below. Looks like I did that locally but forgot to commit this file with the second line...
There was a problem hiding this comment.
Is the noqa necessary now it is actually used?
There was a problem hiding this comment.
I just copied it from the line above. I actually don't know why it was in the previous line - I'm guessing at least someone's PEP8 or similar checker doesn't like the as style or something? I figured safer to be consistent with the line just above.
There was a problem hiding this comment.
I think we need it because the import is not at the top of module.
There was a problem hiding this comment.
That's true for si.py as well...
| @staticmethod | ||
| def _generate_unit_names(): | ||
| from ... import units as u | ||
| from ...units import deprecated as u_deprecated |
There was a problem hiding this comment.
Do you also have to import "vounit_needed" here?
There was a problem hiding this comment.
yep, that's why the tests were failing - in fact it's supposed to be only that
| - {1} prefixes | ||
| - {2} | ||
| - {3} | ||
| - Only |
There was a problem hiding this comment.
What does "only" mean? Other tables have "yes" or "no". Just by looking at the rendered doc, "only" is cryptic.
There was a problem hiding this comment.
I struggled with this. It's meant to mean "the prefixes, but not the base unit." In the rendered docs you'll see that other columns also pretty clearly say "only the prefixes". I guess I could just leave this column blank for the prefix-only ones? Do you think that would be clearer, @pllim?
There was a problem hiding this comment.
I am inclined with just "yes". As far as user is concerned, it is still a unit but with prefix enabled.
| # -*- coding: utf-8 -*- | ||
| # Licensed under a 3-clause BSD style license - see LICENSE.rst | ||
| """ | ||
| This package defines units required by the VOUnit standard but that are likely |
There was a problem hiding this comment.
Maybe there needs to be a note (can be a comment line if you want) to explain why this could not be in deprecated, so people don't attempt that in the future.
|
Also, I don't see test yet. Do we not need test? Failed on Appveyor, so cancelling Travis: |
| continue | ||
| names[key] = getattr(u, key) | ||
|
|
||
| uwithekey = u if hasattr(u, key) else u_deprecated |
There was a problem hiding this comment.
uwithkey or uwiththekey are more correct. 😉
There was a problem hiding this comment.
The things I do for <80 chars... ;)
There was a problem hiding this comment.
Aha! In fixing the test failure I managed to shrink this down so it can be in the following line and stay <80. So no need to worry about the spelling at all! 😛
|
Just pushed up some changes that I think resolve @pllim's comments (although we shall see if the tests pass...) The one outstanding question is from #5661 (comment) (which got clobbered by an edit) - basically, it's "what's the right name for the module holding the things VOUnit requires but we don't want in the base namespace". In the current version it's |
mhvk
left a comment
There was a problem hiding this comment.
Yet more nitpicks, sorry that this has become quite a bit more work than imagined! But I like the solution very much. Also think the current name is OK, as are the docs.
| # This generates a docstring for this module that describes all of the | ||
| # standard units defined here. | ||
| from .utils import generate_unit_summary as _generate_unit_summary # noqa | ||
| from .utils import generate_prefixonly_unit_summary as _generate_prefixonly_unit_summary # noqa |
There was a problem hiding this comment.
Is the noqa necessary now it is actually used?
| # -*- coding: utf-8 -*- | ||
| # Licensed under a 3-clause BSD style license - see LICENSE.rst | ||
| """ | ||
| This package defines SI prefix ed units that are required by the VOUnit standard |
There was a problem hiding this comment.
Actually, the text reads a bit oddly. How about the following to replace the first
two paragraphs:
This package defines SI prefixed units that are required by the VOUnit standard
but that are rarely used in practice and liable to lead to confusion (such as
``msolMass`` for milli-solar mass). They are in a separate module from
``astropy.units.deprecated`` because they need to be enabled by default for
``astropy.units`` to parse compliant VOUnit strings. As a result, e.g.,
``Unit('msolMass')`` will just work, but to access the unit directly one has to
use ``astropy.units.required_by_vounit.msolMass`` instead of the more
usual route possible for the non-prefixed unit, ``astropy.units.solMass``.
|
|
||
| # This generates a docstring for this module that describes all of the | ||
| # standard units defined here. | ||
| from .utils import generate_unit_summary as _generate_unit_summary # noqa |
There was a problem hiding this comment.
again confused by the # noqa is needed here; it is not there in, e.g., si.py and the routines are used.
Note that the two imports can be combined: from .utils import (... as ..., ... as ...)
There was a problem hiding this comment.
Hadn't noticed it's in si.py. So I'm going to guess this is a hold-over from something in the past/someone's overly picky editor, so will remove them.
|
|
||
| def _enable(): | ||
| """ | ||
| Enable deprecated units so they appear in results of |
There was a problem hiding this comment.
Oops, copy & paste error: these are not deprecated units...
| `~astropy.units.UnitBase.find_equivalent_units` and | ||
| `~astropy.units.UnitBase.compose`. | ||
|
|
||
| This may be used with the ``with`` statement to enable deprecated |
There was a problem hiding this comment.
Probably should remove this, since these are enabled by default.
| from .. import deprecated | ||
| from .. import deprecated, required_by_vounit | ||
| from ... import units as u | ||
| from ...tests.helper import pytest # TODO: Stop using bundled pytest |
There was a problem hiding this comment.
Remove this while you're at it? Or is this just because your PRs are based on a relatively old branch?
There was a problem hiding this comment.
nope, it's that way in master. Will fix.
| # the purposes of this test. | ||
|
|
||
| with pytest.raises(AttributeError): | ||
| #nano-solar mass/rad/lum shouldn't be in the base unit namespace |
|
I'm fine with the name, but let me throw out |
|
|
|
|
|
Used the fancy web conflict resolution thingie for the first time... worked well, so merging! |
|
(Also the last commit's errors aren't real - I killed the travis job so that our queue won't be so jammed up) |
|
@eteq - Why is that last one a merge commit? |
|
Great! (but github adding merge commits perhaps a bit less great, though perhaps it doesn't matter?) |
I guess we should avoid "fancy web conflict resolution thingie" in the future? |
|
Or put bigger pressure to GH to fix it and finally offer a rebase button ;) |
In pull request astropy#5661 it was decided that the prefixed versions of `solLum`, `solMass` and `solRad` units should not be present in the main `units` namespace. However, they are valid units in the VOUnit format, so they are defined in a separate `required_by_vounit` module. Furthermore, because the `"generic"` format is supposed to be a superset of the other formats then parsing those units should work with the `"generic"` format too. Previously the `required_by_vounit` module added its units to the registry the `"generic"` format uses, but that was a side-effect of `required_by_vounit` being imported, which happened by using the `"vounit"` format. Now the `"generic"` formatter can be used to parse those units even if `"vounit"` has not been used yet.
This is a possibly-controversial PR with a simple change: it removes the "prefixed" versions of the jupiter/earth/sun masses.
My justification here is that I've never heard anyone speak of a "kiloearth mass" or "milliearth mass". For solar masses it's potentially arguable that "kilosun" or "megasun" should exist in galactic contexts, but I still don't think anyone would say "mega solar mass" even if they do say something like that. And I just encountered someone who was learning about units for the first time and got confused by "mearthMass", thinking it was earth mass, as opposed to "milli-earth mass".
In principal we should deprecate these for a version... but I don't think there's any way to deprecate a unit, is there?
cc @keflavich, as author of c657ca0 which added them for jupiter/earth.