Skip to content

Add milli- prefix to Angstrom unit - #11788

Merged
mhvk merged 2 commits into
astropy:mainfrom
roytsmart:add-milliangstrom
May 27, 2021
Merged

mhvk merged 2 commits into
astropy:mainfrom
roytsmart:add-milliangstrom

Conversation

@roytsmart

@roytsmart roytsmart commented May 26, 2021 •

Copy link
Copy Markdown
Contributor

Description

Added milli- prefix to Angstrom unit

Fixes #11745

@github-actions github-actions Bot added the units label May 26, 2021

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Welcome to Astropy 👋 and congratulations on your first pull request! 🎉

A project member will respond to you as soon as possible; in the meantime, please have a look over the Checklist for Contributed Code and make sure you've addressed as many of the questions there as possible.

If you feel that this pull request has not been responded to in a timely manner, please leave a comment mentioning our software support engineer @embray, or send a message directly to the development mailing list. If the issue is urgent or sensitive in nature (e.g., a security vulnerability) please send an e-mail directly to the private e-mail [email protected].

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, looks all good. I'll merge once all the tests have passed.

@mhvk mhvk added the zzz 💤 merge-when-ci-passes Do not use: We have auto-merge option now. label May 26, 2021
@pllim pllim added this to the v5.0 milestone May 26, 2021
@pllim

pllim commented May 26, 2021

Copy link
Copy Markdown
Member

Shouldn't there be a test too?

@mhvk

mhvk commented May 26, 2021

Copy link
Copy Markdown
Contributor

The automatic going through all units should be good enough. But I note there is a failure in the doctests, plus a real error because mÅ was used in a test to check that it failed.

@byrdie - do you think you'll be able to fix this? If you feel it is too tricky, I can do it for you.

@roytsmart

roytsmart commented May 26, 2021 via email •

Copy link
Copy Markdown
Contributor Author

@dhomeier

Copy link
Copy Markdown
Contributor

This works in some unexpected way in that it enables u.mAngstrom, u.milliAA and u.milliangstrom rather than u.mAA and u.milliAngstrom - the reason being evidently that for def_unit

the first element is the canonical (short) name, and the rest of the elements are aliases.

It might seem more logical then to define it as

def_unit(['AA', 'Angstrom', 'angstrom'], ...

but that would break e.g. the expected fits format outputs.
As a kind of alternative workaround you might instead define both prefix versions as aliases for both the short and long form:

    prefixes=[(['m', 'milli'], ['milli', 'm'], 1.e-3)],

You will also have to update the matches for test_units:test_suggestions to

    ('ångström', 'Angstrom, angstrom, mAngstrom or mangstrom')

@roytsmart

Copy link
Copy Markdown
Contributor Author

@dhomeier, thanks for explaining that, I had not yet figured out why that test was failing.
I'll add the workaround you posted and update the other test you mentioned.

@dhomeier dhomeier left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If tests are passing after the fix, this is good to go, but I'd let @mhvk have a second look if he agrees with the multiple alias solution.

Comment thread astropy/units/tests/test_units.py Resolved
@mhvk
mhvk force-pushed the add-milliangstrom branch from 9fe784b to 9dce8bb Compare May 27, 2021 15:49

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@byrdie - there was still a failure in a doctest (in which milliangstrom is now offered - correctly - as an alternative). I went ahead and pushed a change for that to your branch, also squashing your comments in the process. I hope that with this all the tests will pass, because the rest looks all OK. So, I'll approve and merge if tests indeed pass.

Thanks!

@dhomeier

Copy link
Copy Markdown
Contributor

@mhvk this does raise some concerns that similar problems might pop up downstream if looking for the expected exception. But I don't really see a good alternative if we want to accept u.mAA (and I definitely think we should).
One option could be to allow only 'milli' as 'short' prefix, backwards as it may seem
prefixes=[(['milli'], ['milli', 'm'], 1.e-3)],
but that would still only get rid of mAngstrom, not mangstrom, so maybe not much point in it.

@roytsmart

Copy link
Copy Markdown
Contributor Author

@mhvk, thanks for updating the doctest. I didn't know if I was supposed to update the .rst file directly or if there was a docstring in
a .py file somewhere that I had to fix.

@mhvk

mhvk commented May 27, 2021

Copy link
Copy Markdown
Contributor

@byrdie - yes, I thought this was getting a bit beyond what a supposedly quick PR should do, especially as with those doctests it is often a bit trickier than thought. Anyway, tests pass now and @dhomeier also agrees this is all OK, so I'll merge. Thanks again, and of course other suggestions for making astropy just a little bit better are very welcome!

@mhvk
mhvk merged commit bfcdb53 into astropy:main May 27, 2021
@mhvk

mhvk commented May 27, 2021

Copy link
Copy Markdown
Contributor

p.s. @dhomeier - I agree that the mAngstrom is really not all that great, but ended up also agreeing that if mangstrom is in there, we should just not perfect be the enemy of good enough. It would have been nicer if the names could just have been swapped, so that AA was first.

@dhomeier

Copy link
Copy Markdown
Contributor

Thanks @byrdie and congrats to completing the first PR into Astropy!

@roytsmart

Copy link
Copy Markdown
Contributor Author

Thanks @mhvk, @dhomeier and everyone else for your help and allowing me the opportunity to contribute!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

units zzz 💤 merge-when-ci-passes Do not use: We have auto-merge option now.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add milli- prefix to Angstrom unit

4 participants