Navigation Menu

Skip to content
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

Raise NotImplementedError when parsing with output-only format #11829

Merged
merged 1 commit into from Jun 9, 2021

Conversation

mhvk
Copy link
Contributor

@mhvk mhvk commented Jun 9, 2021

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
Copy link
Member

@pllim pllim left a comment

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
Copy link
Contributor Author

mhvk commented Jun 9, 2021

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
Copy link
Contributor Author

mhvk commented Jun 9, 2021

@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
Copy link
Member

olebole commented Jun 9, 2021

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
Copy link
Contributor Author

mhvk commented Jun 9, 2021

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