Skip to content

Allow unit parser to deal with more unicode representations - #11827

Merged
pllim merged 3 commits into
astropy:mainfrom
mhvk:units-unicode-update
Jun 10, 2021
Merged

pllim merged 3 commits into
astropy:mainfrom
mhvk:units-unicode-update

Conversation

@mhvk

@mhvk mhvk commented Jun 9, 2021

Copy link
Copy Markdown
Contributor

Specifically, ensures that for non-composite units, u.Unit(unit.to_string('unicode')) now correctly round-trips.

Fixes #11826

Note that to me it is a cross between a bugfix and feature request. I think it is fine to just have it in 5.0, and not backport.

@mhvk
mhvk force-pushed the units-unicode-update branch from 971b7c2 to b8c2f07 Compare June 9, 2021 17:12
@pllim
pllim requested a review from olebole June 9, 2021 17:14
@mhvk
mhvk requested a review from dhomeier June 9, 2021 17:37

@olebole olebole left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks fine for me; thank you very much.

@pllim

pllim commented Jun 9, 2021

Copy link
Copy Markdown
Member

@mhvk , do you also want to address #11829 (comment) here?

'\N{PRIME}': 'arcmin',
'\N{DOUBLE PRIME}': 'arcsec',
'\N{MODIFIER LETTER SMALL H}': 'hourangle',
'e\N{SUPERSCRIPT MINUS}': 'electron',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

how is e⁻ a unit?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Predates me, but I think meant to be CCD counts or so,

def_unit(['electron'], doc="Number of electrons", namespace=_ns,
format={'latex': r'e^{-}', 'unicode': 'e⁻'})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, I used it at some point to go from photons --> electrons --> adu in an ETC.


_prefixable_unit_symbols = {
'\N{GREEK CAPITAL LETTER OMEGA}': 'Ohm',
'\N{LATIN CAPITAL LETTER A WITH RING ABOVE}': 'Angstrom',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this mean things like mÅ are now allowed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Only the prefixes that are allowed with 'Angstrom' generally - which indeed includes mÅ (#11788) but nothing else. Of course, we already had kOhm, etc.

@mhvk

mhvk commented Jun 9, 2021

Copy link
Copy Markdown
Contributor Author

@pllim - see #11831 (rather keep it separate!)

@pllim

pllim commented Jun 10, 2021

Copy link
Copy Markdown
Member

I'll wait for @maxnoe 's discussion to wrap up before approving.

@maxnoe

maxnoe commented Jun 10, 2021

Copy link
Copy Markdown
Member

I'll wait for @maxnoe 's discussion to wrap up before approving.

These were more FYI questions, so please just go ahead

@pllim pllim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, all!

@pllim
pllim merged commit a394e3d into astropy:main Jun 10, 2021
@mhvk
mhvk deleted the units-unicode-update branch June 10, 2021 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unit roundtrips do not always work

4 participants