You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was surprised how complex the exception is when trying to create a unit for an invalid string.
Would it be possible / make sense to simplify this and present a non-chained exception to the user in that case?
This is with Astropy 3.0.3 on Python 3.6, I did not check other versions.
>>> import astropy.units as u
>>> u.Unit('spam')
Traceback (most recent call last):
File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astropy/units/format/generic.py", line 482, in _do_parse
return cls._parse_unit(s, detailed_exception=False)
File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astropy/units/format/generic.py", line 462, in _parse_unit
raise ValueError()
ValueError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astropy/units/format/generic.py", line 443, in _get_unit
return cls._parse_unit(t.value)
File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astropy/units/format/generic.py", line 460, in _parse_unit
s, did_you_mean(s, registry)))
ValueError: spam is not a valid unit.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astropy/units/core.py", line 1784, in __call__
return f.parse(s)
File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astropy/units/format/generic.py", line 469, in parse
result = cls._do_parse(s, debug=debug)
File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astropy/units/format/generic.py", line 485, in _do_parse
return cls._parser.parse(s, lexer=cls._lexer, debug=debug)
File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astropy/extern/ply/yacc.py", line 331, in parse
return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astropy/extern/ply/yacc.py", line 1061, in parseopt_notrack
lookahead = get_token() # Get the next token
File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astropy/extern/ply/lex.py", line 350, in token
newtok = func(tok)
File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astropy/units/format/generic.py", line 151, in t_UNIT
t.value = cls._get_unit(t)
File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astropy/units/format/generic.py", line 447, in _get_unit
t.lexpos, str(e)))
ValueError: At col 0, spam is not a valid unit.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/deil/software/anaconda3/envs/gammapy-dev/lib/python3.6/site-packages/astropy/units/core.py", line 1798, in __call__
raise ValueError(msg)
ValueError: 'spam' did not parse as unit: At col 0, spam is not a valid unit.
The text was updated successfully, but these errors were encountered:
I was surprised how complex the exception is when trying to create a unit for an invalid string.
Would it be possible / make sense to simplify this and present a non-chained exception to the user in that case?
This is with Astropy 3.0.3 on Python 3.6, I did not check other versions.
The text was updated successfully, but these errors were encountered: