VOTable unit format#11032
Conversation
The VOTable unit format should depend on its version (see issue astropy#10791). This commit adds a test that checks if the different VOTable versions have the correct unit format associated with them.
Because the unit format of a VOTable depends on its version the Field class must have access to this information, including in the test functions. This commit adds a function to VOTableFile that creates the appropriate Boolean flags. The same function can also be used in the VOTableFile parse() and to_xml() methods.
Using angstroms with the 'vounit' format raises a UnitsWarning that suggests angstroms should not be used. This warning causes test_votable_quantity_write() to fail even though the functionality of the underlying code is not compromised. Replacing angstroms with something else allows the test to pass.
mhvk
left a comment
There was a problem hiding this comment.
This looks all good to me - some nitpickly comments only. That said, as I'm really not familiar with vounit, I'd prefer to have @tomdonaldson sign off (in particular on choice of name/location of test/etc.
Also, for sure this needs an entry in CHANGES.rst! I guess one question is whether this is a bug fix and thus should be backported.
| config=None, pos=None, **extra): | ||
| if config is None: | ||
| config = {} | ||
| if hasattr(votable, '_get_version_flags'): |
There was a problem hiding this comment.
Is it possible to pass in an old table?
There was a problem hiding this comment.
I do not know if it is possible to pass in an old table, but without this change two tests fail because the correct unit format could not be determined.
There was a problem hiding this comment.
OK, sounds like it is necessary, then, though I'll leave this to @tomdonaldson just to be sure.
There was a problem hiding this comment.
I was wondering about this check as well. I think it is OK since It seems necessary to protect the unit tests which are exercising Field without a containing votable. Testing Field that way (or designing Field that way) may be questionable, but addressing those questions would be outside the scope of this PR.
|
|
||
|
|
||
| def test_unit_format(): | ||
| from astropy.io.votable.table import parse |
| self.groups.append(group) | ||
| group.parse(iterator, config) | ||
|
|
||
| def _get_version_flags(self): |
There was a problem hiding this comment.
I'd maybe call this _get_version_checks or _get_version_info
| """ | ||
| t = QTable() | ||
| t['a'] = u.Quantity([1, 2, 4], unit='Angstrom') | ||
| t['a'] = u.Quantity([1, 2, 4], unit='m') |
There was a problem hiding this comment.
Does the new format not support Angstrom? My tendency would then be to use 'nm' to at least keep it a prefixed unit.
There was a problem hiding this comment.
Angstroms are supported but discouraged, so using them raises a UnitsWarning which seems to cause this test to fail. Running pytest -P table -p no:warnings does succeed.
There was a problem hiding this comment.
OK, let's use 'nm' instead, then.
|
This is the current warning about an invalid unit string in a VOTable: astropy/astropy/io/votable/exceptions.py Line 1040 in 790332a It is correct for the older VOTable versions, but for newer ones the warning should refer to the VOUnit specification instead. Should I add W56 with the appropriate reference for use with the newer VOTables? |
|
@eerovaher - yes, seems good to update the warning too! (though again, I know very little about VOTable - I was asked because of |
Yes, I think it would be great to add that new unit information to the warning(s). Would it be easier to add the info to the existing warning so that the one warning covers both cases? I don't have a strong opinion one way or the other. I did notice some confusion in the related issue #10791 regarding the most up-to-date VOUnits specification. (It looks like there is a mixup in some IVOA document URL redirects.) The best URL for the latest VOUnits specification is: https://www.ivoa.net/documents/VOUnits |
tomdonaldson
left a comment
There was a problem hiding this comment.
Thanks very much @eerovaher for this PR, and @mhvk for the review.
I agree with the analysis regarding the versioning of units with respect to VOTable version, i.e. that the change in official VOTable unit syntax from cds to vounit occurs with VOTable 1.4.
I also agree that these changes fix the behavior correctly, so I will approve this with an update to the warning(s) as discussed.
Since this behavior should have been included with the initial support for VOTable 1.4, this should probably be treated as a bug fix and backported.
The unit format of a VOTable is version-dependent. The docstring of the VOTable invalid unit string warning (W50) should therefore contain references to both the old and the new unit format specification.
|
I have updated W50 and I can update |
|
@eerovaher thanks, this looks great. Although this is fixing a bug from 4.0, I'm second guessing whether or not it warrants a backport. Would a 4.3 release meet your needs? |
|
I don't have a preference for which release this should be included in. |
OK, sounds good. I'll leave the milestone at 4.3 then. |
tomdonaldson
left a comment
There was a problem hiding this comment.
This all looks good. Thanks again for these changes!
|
Hmm, my bad, my issue is not with this PR, but with another one. I'm sorry about the noise. |
The unit format of a VOTable is version dependent. Astropy has the capability of parsing the new unit format, but nonetheless assumes all VOTables are using the old unit specification.
This pull request would make Astropy use the old
'cds'unit format up until VOTable version 1.3 and the new'vounit'unit format starting from VOTable version 1.4.Addresses #10791