Skip to content

Raise NotImplementedError when parsing with output-only format - #11829

Merged
mhvk merged 1 commit into
astropy:mainfrom
mhvk:unit-parsing-wrong-format
Jun 9, 2021
Merged

mhvk merged 1 commit into
astropy:mainfrom
mhvk:unit-parsing-wrong-format

Conversation

@mhvk

@mhvk mhvk commented Jun 9, 2021 •

Copy link
Copy Markdown
Contributor

EDIT: Really, just resolving over-eager exception catching...

Previously,

u.Unit('m', format='unicode')
...
ValueError: 'm' did not parse as unicode unit: Can not parse Unicode If this is meant to be a custom unit, define it with 'u.def_unit'. To have it recognized inside a file reader or other code, enable it with 'u.add_enabled_units'. For details, see https://docs.astropy.org/en/latest/units/combining_and_defining.html

Now:

NotImplementedError: Can not parse with Unicode format

fixes #11828

milestone'd 5.0, since really this is just a change in error type.

cc @olebole, @pllim

@mhvk mhvk added this to the v5.0 milestone Jun 9, 2021
@mhvk
mhvk requested a review from pllim June 9, 2021 17:53
@pllim
pllim requested a review from olebole June 9, 2021 18:06

@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.

Seems uncontroversial to me but I'll leave it open for Ole's review.

@mhvk mhvk mentioned this pull request Jun 9, 2021
@mhvk

mhvk commented Jun 9, 2021

Copy link
Copy Markdown
Contributor Author

Am merging since it will help get me out of rebase problems in #11830...

@mhvk
mhvk merged commit 372fc7b into astropy:main Jun 9, 2021
@mhvk

mhvk commented Jun 9, 2021

Copy link
Copy Markdown
Contributor Author

@olebole - input is still welcome! If you see problems, I'll fix separately...

@mhvk
mhvk deleted the unit-parsing-wrong-format branch June 9, 2021 18:49
@olebole

olebole commented Jun 9, 2021 •

Copy link
Copy Markdown
Member

No problems, however my point was that the message with an unknown input format is confusing:

>>> u.Unit('Ω', format='foo')
[…]
ValueError: Unknown format 'foo'.  Valid formatter names are: [base, generic, unscaled, cds, console, fits, latex, latex_inline, ogip, unicode, vounit]

This error says that unicode is a valid format(ter) here, which then does not work. IMO the list shown in this ValueError should contain only the formatters that really can parse any input.

@mhvk

mhvk commented Jun 9, 2021

Copy link
Copy Markdown
Contributor Author

Hmm, that is actually fairly tricky, since the unknown format error is raised in units.format.get_format() and that doesn't know a parser is desired. But maybe #11831 is at least a step on the way?

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 constructor should not allow formats that are for output only

3 participants