question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

VOUnit to issue VOWarning rather than generic UnitsWarning

See original GitHub issue

astropy.io.votable.exceptions.W50 is defined to be the warning for units that do not adhere to the VO standards: https://www.ivoa.net/documents/VOUnits

yet, astropy.units.format.vounit.VOUnit issues a generic UnitsWarning for the exact same reason.

This is somewhat unexpected in practice, and while in the example below we could ignore both, I don’t think that’s the right approach:

https://github.com/astropy/astroquery/issues/2352

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:16 (16 by maintainers)

github_iconTop GitHub Comments

4reactions
eerovahercommented, Mar 31, 2022

If we look at the code that parses the VOTable then we see that it should already properly replace any UnitsWarning instances with W50: https://github.com/astropy/astropy/blob/acdefa2cdde7b1dd5923e7acece15eca7812d127/astropy/io/votable/tree.py#L1390-L1404 The fact that we still get an UnitsWarning despite parse_strict='silent' means that there is a bug that would not be fixed by changing the warnings hierarchy, so that does not sound like a solution we should pursue. Indeed, the underlying bug can be easily confirmed if we try out different unit formats. With e.g. format='cds' everything works as expected:

>>> from astropy import units as u
>>> u.Unit('e-/s', format='cds', parse_strict='raise')
...
ValueError: 'e-/s' did not parse as cds unit: Syntax error If this is meant to be a custom unit...
>>> u.Unit('e-/s', format='cds', parse_strict='warn')
WARNING: UnitsWarning: 'e-/s' did not parse as cds unit: Syntax error If this is meant to be a custom unit...
UnrecognizedUnit(e-/s)
>>> u.Unit('e-/s', format='cds', parse_strict='silent')
UnrecognizedUnit(e-/s)

But now with format='vounit':

>>> u.Unit('e-/s', format='vounit', parse_strict='raise')
WARNING: UnitsWarning: Unit 'e' not supported by the VOUnit standard.  [astropy.units.format.vounit]
...
ValueError: 'e-/s' did not parse as vounit unit: Invalid character at col 1 If this is meant to be a custom unit...
>>> u.Unit('e-/s', format='vounit', parse_strict='warn')
WARNING: UnitsWarning: Unit 'e' not supported by the VOUnit standard.  [astropy.units.format.vounit]
WARNING: UnitsWarning: 'e-/s' did not parse as vounit unit: Invalid character at col 1 If this is meant to be a custom unit...
UnrecognizedUnit(e-/s)
>>> u.Unit('e-/s', format='vounit', parse_strict='silent')
WARNING: UnitsWarning: Unit 'e' not supported by the VOUnit standard.  [astropy.units.format.vounit]
UnrecognizedUnit(e-/s)

We can see that using format='vounit' always results in an additional warning, which is the real bug that needs to be fixed.

2reactions
eerovahercommented, Apr 2, 2022

Turns out the bug we uncovered here was reported already years ago: #6302

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vizier search often emits UnitsWarning: Unit 'e' not ...
When performing Vizier search, it often emits the following (arguably useless) warning. UnitsWarning: Unit 'e' not supported by the VOUnit ...
Read more >
Source code for astropy.units.format.vounit
Source code for astropy.units.format.vounit ... Generic): """ The IVOA standard for units used by the VO. ... UnitsWarning) return cls.
Read more >
Source code for astropy.units.format.vounit
Source code for astropy.units.format.vounit ... Generic): """ The IVOA standard for units used by the VO. ... UnitsWarning) return cls.
Read more >
sUnit incorrectly claims to rely on UIP - Coq/Coq
VOUnit to issue VOWarning rather than generic UnitsWarning, 16, 2022-03-30, 2022-08-06. Text flowing off the page, 1, 2021-02-09, 2022-08-17.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found