astropy/astropy — pull request #2806 by mdboom (2014-07-31 18:13:45+00:00)
Title: Provide more detailed feedback about deprecated units.

Based on some discussion on the astropy mailing list, this improves some error messages to provide better feedback about deprecated units in the various unit formats. We still may want to augment this with frequently seen invalid units and hand-written suggestions, but this doesn't do that yet.

This does two things:

- When the unit is totally unknown, but has a close match, any suggestions it gives that are deprecated will be marked as such. It doesn't make sense to just not give those suggestions, because sometimes there is no better alternative to offer.

- When a deprecated unit is created, and there is a warning, the warning will suggest a non-deprecated alternative if available.

Examples are worth 1000 words:

```
In [1]: import astropy.units as u

# For FITS, we really can't provide a good alternative for angstrom, since the format doesn't
# support scaled units
In [2]: u.Unit("ANGSTROM", format="fits")
ValueError: 'ANGSTROM' did not parse as fits unit: At col 0, Unit 'ANGSTROM' not supported by the FITS standard. Did you mean Angstrom (deprecated) or angstrom (deprecated)?

In [3]: u.Unit("Angstrom", format="fits")
WARNING: UnitsWarning: The unit 'Angstrom' has been deprecated in the fits standard.

# However, for VOUnit, we can recommend using `1 10-10m` instead
In [5]: u.Unit("angstrom", format="vounit")
WARNING: UnitsWarning: The unit 'angstrom' has been deprecated in the vounit standard. Suggested: '1 10-10m'. [astropy.units.format.utils]

In [6]: u.Unit("erg", format="vounit")
WARNING: UnitsWarning: The unit 'erg' has been deprecated in the vounit standard. Suggested: '1 10-7kg m2 s-2'. [astropy.units.format.utils]
Out[6]: Unit("erg")

In [7]: u.Unit("sun", format="vounit")
ValueError: 'sun' did not parse as vounit unit: At col 0, Unit 'sun' not supported by the VOUnit standard. Did you mean Sun (deprecated) or uN?
```