Skip to content

Recommend alternatives when a unit isn't found - #1870

Merged
mdboom merged 6 commits into
astropy:masterfrom
mdboom:unit/recommend
Dec 30, 2013
Merged

mdboom merged 6 commits into
astropy:masterfrom
mdboom:unit/recommend

Conversation

@mdboom

@mdboom mdboom commented Dec 6, 2013

Copy link
Copy Markdown
Contributor

This presents helpful exceptions with "closely matched" units (using difflib).

In [2]: u.Unit("microns")
ERROR: ValueError: 'microns' did not parse as unit: At col 0, microns
is not a valid unit. Did you mean micron? [astropy.units.core]

In [3]: u.Unit("s/microns")
ERROR: ValueError: 's/microns' did not parse as unit: At col 2, microns
is not a valid unit. Did you mean micron? [astropy.units.core]

In [4]: u.Unit("M")
ERROR: ValueError: 'M' did not parse as unit: At col 0, M is not a valid
unit. Did you mean m? [astropy.units.core]

In [5]: u.Unit("metre")
ERROR: ValueError: 'metre' did not parse as unit: At col 0, metre is not
a valid unit. Did you mean meter? [astropy.units.core]

In [6]: u.Unit("angstroms")
ERROR: ValueError: 'angstroms' did not parse as unit: At col 0, 
angstroms is not a valid unit. Did you mean angstrom? [astropy.units.core]

In [7]: u.Unit("milimeter")
ERROR: ValueError: 'milimeter' did not parse as unit: At col 0, 
milimeter is not a valid unit. Did you mean millimeter? [astropy.units.core]

It also simplifies some unit parsing error messages so they don't contain so much redundant information.

Before:

ValueError: 'm/s/s' did not parse as unit format 'generic': Syntax error parsing unit string 'm/s/s'

After:

ValueError: 'm/s/s' did not parse as unit: Syntax error

@mdboom

mdboom commented Dec 6, 2013

Copy link
Copy Markdown
Contributor Author

This at least somewhat addresses #1520.

@mdboom

mdboom commented Dec 6, 2013

Copy link
Copy Markdown
Contributor Author

@embray: Any opinions about milestoning this? It definitely doesn't change the API, but it's not really a bugfix either...

@pllim

pllim commented Dec 6, 2013

Copy link
Copy Markdown
Member

👍

@astrofrog

Copy link
Copy Markdown
Member

I don't have a strong preference of 0.3.1 vs 0.4.0. @embray?

@mdboom

mdboom commented Dec 10, 2013

Copy link
Copy Markdown
Contributor Author

Closes #1520.

mdboom added a commit that referenced this pull request Dec 30, 2013
Recommend alternatives when a unit isn't found
@mdboom
mdboom merged commit 50289dd into astropy:master Dec 30, 2013
mdboom added a commit that referenced this pull request Feb 12, 2014
Recommend alternatives when a unit isn't found
mdboom added a commit that referenced this pull request Feb 12, 2014
Recommend alternatives when a unit isn't found
@mdboom
mdboom deleted the unit/recommend branch May 21, 2014 23:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants