Improve error message for `quantity_input` when physical type is unknown
- Dominant language
- Python
- Stars
- 5.3k
- Forks
- 2.2k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 75
Description
When `astropy.units.quantity_input` is used for an `"unknown"` physical type, the error message currently does not give information about what the physical type should be. As an example, let's define...
```python
import astropy.units as u
angle = u.get_physical_type("angle")
@u.quantity_input(x=angle)
def f(x):
return x
```
Then the error message for a `Quantity` with the incorrect physical type will be...
```pycon
>>> f(1 * u.m)
astropy.units.core.UnitsError: Argument 'x' to function 'f' must be in units convertible to 'unknown'.
```
We should change the error message so that instead of `must be in units convertible to 'unknown'`, it should give a specific set of units that are compatible with the unknown physical type, perhaps something like `must be in units convertible to 1 / rad`.
Many thanks to @dhomeier for noticing this in the `#units` channel on Slack!
Contributor guide
Research direction
Start by reading the astropy.units.quantity_input entry point and reproduce the example with an unknown physical type and an incompatible Quantity. Trace how the current UnitsError text is built; done means the message identifies a compatible unit set or representative unit instead of reporting only 'unknown'.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100