Skip to content

Ensure that the CDS unit parser can deal with '[-]' - #11250

Merged
mhvk merged 5 commits into
astropy:masterfrom
mhvk:units-cds-log10-dimensionless
Jan 16, 2021
Merged

mhvk merged 5 commits into
astropy:masterfrom
mhvk:units-cds-log10-dimensionless

Conversation

@mhvk

@mhvk mhvk commented Jan 14, 2021

Copy link
Copy Markdown
Contributor

In #11239, it became clear that while the CDS unit parser recognizes dex units with the [...] signature, it does not parse [-] for u.dex(u.one). This PR fixes that bug, meaning that CDS readme for tables that have these units can now be read (more) correctly.

In [2]: u.Unit('[-]', format='cds')
Out[2]: Unit("dex(-)")
n [3]: u.Unit('[-]', format='cds').to_string(format='cds')
Out[3]: '[-]'

@taldcroft taldcroft left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from the trivial change log suggestion, this looks great from the ascii.io perspective. I can't really comment on the units code itself.

Comment thread CHANGES.rst Resolved
@mhvk
mhvk force-pushed the units-cds-log10-dimensionless branch from 3edf4de to 5a24873 Compare January 15, 2021 23:04
@mhvk
mhvk merged commit b3a328d into astropy:master Jan 16, 2021
@mhvk
mhvk deleted the units-cds-log10-dimensionless branch January 16, 2021 00:48
@bsipocz

bsipocz commented Jan 27, 2021

Copy link
Copy Markdown
Member

This introduced a regression into the astroquery tests. Probably not a big deal and we have to fix it in our tests, but others may run into it, too:

Prior to this:

>>> from astroquery.imcce import Miriade
>>> result = Miriade.get_ephemerides('3552', coordtype=5)
>>> result['airmass']
UnrecognizedUnit(-)
>>> result['airmass'].unit == '-'
True
>>> result['airmass'].unit.find_equivalent_units()
AttributeError: 'UnrecognizedUnit' object has no attribute 'find_equivalent'

After:

>>> result['airmass']
Unit("---")
>>> result['airmass'].unit.find_equivalent_units()
  Primary name | Unit definition | Aliases
[
  percent      | 0.01            | pct     ,
]

The raw votable returns can be accessed as e.g. (which is then parsed with astropy.io.votable.parse):

from io import BytesIO
response = Miriade.get_ephemerides_async('3552', coordtype=5)
voraw = BytesIO(response.content)

@pllim

pllim commented Jan 27, 2021

Copy link
Copy Markdown
Member

Is Unit("---") supposed to resolve to percent? 👀

@mhvk

mhvk commented Jan 27, 2021

Copy link
Copy Markdown
Contributor Author

Unit('---') is dimensionless, so percent is equivalent...

@mhvk

mhvk commented Jan 27, 2021

Copy link
Copy Markdown
Contributor Author

Of course, we should not forget the advantage of the change: now np.arccos(1/result['airmass']) will actually work!

@bsipocz

bsipocz commented Jan 27, 2021

Copy link
Copy Markdown
Member

I'm not saying it's not an improvement, but I had a hard time to find which change actually caused this, just by reading the changelogs (first I assumed it's because of the votable unit parsing change in io.votable, but in fact it was due to this (did I mention yet that I really love git bisect?)

Comment thread CHANGES.rst
- For ``Quantity.to_string()``, ensure that the precision argument is also
used when the format is not latex. [#11145]

- For CDS units and tables, recognize ``-`` as indicating dimensionless and

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bsipocz - changelog entries are always so darn tricky. Would it have helped to include --- here? Happy to make quick PR to change it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it would have helped. I started with the changelog, then tried to grep for it in the diff before falling back to the heavy machinery of git bisect.

@astrofrog

Copy link
Copy Markdown
Member

@mhvk - is this critical to backport to LTS? There are quite a few conflicts due to the fact #9971 is not included in LTS, so it's a tricky backport and I would prefer to only include it if it's really essential.

@mhvk

mhvk commented Mar 16, 2021

Copy link
Copy Markdown
Contributor Author

@astrofrog - Given that not having #9971 meant that logarithmic units didn't work properly in LTS anyway, I think we should just not backport this one either. Should have seen that at the time....

@astrofrog astrofrog modified the milestones: v4.0.5, v4.2.1 Mar 16, 2021
@astrofrog

Copy link
Copy Markdown
Member

Ok thanks for the quick reply!

pllim pushed a commit to pllim/astropy that referenced this pull request Mar 24, 2021
Ensure that the CDS unit parser can deal with '[-]'
@mhvk

mhvk commented Mar 24, 2021

Copy link
Copy Markdown
Contributor Author

Now seeing #11418, should the changelog entry be moved to 4.2.1 in master too!?

eteq added a commit that referenced this pull request Mar 25, 2021
Manual backport of #11250 (Ensure that the CDS unit parser can deal with '[-]')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants