Repository navigation
Parse CDS units with Unit 'cds' format. - #7348
Conversation
|
Hi there @kyleaoman 👋 - thanks for the pull request! I'm just a friendly 🤖 that checks for issues related to the changelog and making sure that this pull request is milestoned and labeled correctly. This is mainly intended for the maintainers, so if you are not a maintainer you can ignore this, and a maintainer will let you know if any action is required on your part 😃. Everything looks good from my point of view! 👍 If there are any issues with this message, please report them here. |
|
@kyleaoman - can you add the example you mention as a unit test for the CDS reader? |
|
Added a test. I merged changes from astropy/master in my branch a while ago, which I now see from the instructions was a bad idea. |
|
The change to the cds unit parsing seems to break some other tests, this will need to be looked into... |
|
@kyleaoman - If you could rebase that would be the way to get rid of the merge issues. I'm happy to help with it if needed, just ping me on slack. |
53eddbc to
9701dc9
Compare
|
@astrofrog added the test, checked that it fails before and passes after. Also cleaned up a bit with help from @bsipocz . There are a couple of other tests that now fail, which I'm having some trouble diagnosing. If one of you can help, or can ping someone else who can, that would be much appreciated. |
Corrects a failed test after changes in PR astropy#7348. The CDS specification accepts both 'arcs' and 'arcsec' for arcseconds (and similarly for arcminutes), see http://vizier.u-strasbg.fr/cgi-bin/Unit. 'arcsec' seems to be the preferred form (http://cds.u-strasbg.fr/doc/catstd-3.2.htx, but an argument could be made the other way via 'rule 2' on that page) so make that the default string representation.
|
Seem to have sorted out the issues with failing tests. Looks like all that's missing is a review from @taldcroft. |
| col.unit = None # "---" is the marker for no unit in CDS table | ||
| else: | ||
| try: | ||
| col.unit = Unit(unit, format='cds') |
There was a problem hiding this comment.
I'm not sure we should fail on the unit not parsing correctly - that forces the user to edit the files they downloaded. Instead, I would suggest to follow the fits example and just add parse_strict='warn' or even parse_strict='silent' (which means one get UnrecognizedUnit after all, but of course only for those units that are, in fact, not recognized).
But best to cc @taldcroft, since he will have a better idea about what the standard is in io.ascii (perhaps there is a keyword argument already for it??).
|
I agree that a warning makes more sense than an error if a unit fails to parse. A user can always suppress a warning if they want it to be silent. @taldcroft hopefully this is ready for merge now? |
|
Hm, this 'coverage/coveralls' check is new to me... what exactly should be done to fix that? |
| assert iers_tab['UT1_UTC'].unit is u.second | ||
| assert iers_tab['PM_x'].unit is u.arcsecond | ||
| assert iers_tab['PM_y'].unit is u.arcsecond | ||
| assert (iers_tab['UT1_UTC'].unit / u.second).is_unity() |
There was a problem hiding this comment.
Humm, this is slightly disconcerting. I see the nice commit description that points to why this change was made. For example:
In [5]: u.s is u.Unit('s')
Out[5]: True
In [6]: u.s is u.Unit('s', format='cds')
Out[6]: False
In [7]: u.s / u.s
Out[7]: Unit(dimensionless)
In [8]: u.s / u.Unit('s', format='cds')
Out[8]: Unit("s / s")
I had imagined that the unit format implies how to parse the unit string (or combinations thereof), but that the fundamental units coming out were the same thing. Not so apparently?
So this does imply some risk of breaking code with this PR. Thoughts @mhvk?
|
@kyleaoman - I think for this change it is not necessary to include the two new (large-ish) test files. You could instead just modify the following one to set a unit of You should rebase away those files (basically |
|
As noted by the bot, you need to put in a changelog entry for this. I am labeling this as a bug fix because CDS units should be correctly parsed by the CDS reader, so the entry would go in the bug fix section. However, it is not obvious to me that this is fully backwards compatible because of the issue with units, so as it stands this should NOT be backported. |
|
@kyleaoman - apart from the little technical issues, this looks good, thanks for the contribution! |
|
That cds @taldcroft - could you raise a new issue? |
9dff809 to
5dc98f0
Compare
Corrects a failed test after changes in PR astropy#7348. The CDS specification accepts both 'arcs' and 'arcsec' for arcseconds (and similarly for arcminutes), see http://vizier.u-strasbg.fr/cgi-bin/Unit. 'arcsec' seems to be the preferred form (http://cds.u-strasbg.fr/doc/catstd-3.2.htx, but an argument could be made the other way via 'rule 2' on that page) so make that the default string representation.
5dc98f0 to
28d5a15
Compare
|
@taldcroft Alright, think all the requested changes are handled, and everything checks out on the automated tests now. |
| 't/fixed_width_2_line.txt', | ||
| 't/cds/description/ReadMe', | ||
| 't/cds/description/table.dat', | ||
| 't/cds/units/ReadMe', |
Corrects a failed test after changes in PR astropy#7348. The CDS specification accepts both 'arcs' and 'arcsec' for arcseconds (and similarly for arcminutes), see http://vizier.u-strasbg.fr/cgi-bin/Unit. 'arcsec' seems to be the preferred form (http://cds.u-strasbg.fr/doc/catstd-3.2.htx, but an argument could be made the other way via 'rule 2' on that page) so make that the default string representation.
Comparisons fail with some units parsed from strings, some
examples are below. I think the last should be preferred.
u.Unit('s') is u.Unit('second') # True
u.Unit('s') is u.Unit('sec', format='cds') # False
u.Unit('s') is u.Unit('sec', format='cds').represents # True
u.ms is u.Unit('ms', format='cds').represents # False
(u.ms / u.Unit('ms', format='cds')).is_unity() # True
Added a bogus unit to an existing sample CDS format file to test parsing of cds-formatted units. Adjusted unrelated test which uses the same file.
28d5a15 to
bd67f66
Compare
|
@taldcroft and done. |
taldcroft
left a comment
There was a problem hiding this comment.
Thanks @kyleaoman ! Definitely appreciate getting help here to get the details just right.
Corrects a failed test after changes in PR astropy#7348. The CDS specification accepts both 'arcs' and 'arcsec' for arcseconds (and similarly for arcminutes), see http://vizier.u-strasbg.fr/cgi-bin/Unit. 'arcsec' seems to be the preferred form (http://cds.u-strasbg.fr/doc/catstd-3.2.htx, but an argument could be made the other way via 'rule 2' on that page) so make that the default string representation.
The astropy.units.Unit class has an option 'format' in the constructor which accepts a parameter 'cds' so that units formatted conforming to the CDS standard can be parsed correctly. This change sets the column units of the read table using this feature. Previously, the columns of the read table would have units of type UnrecognizedUnit (basically a glorified string) in many cases - I stumbled on this when trying to read a table with a column in GMsun (giga-solar-masses). I believe this should be fully backwards-compatible from a user point of view.
The following snippet will fail before this change, and succeed after: