Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix vounit formatting of fractions and powers #15282

Merged
merged 4 commits into from Sep 7, 2023

Conversation

olebole
Copy link
Member

@olebole olebole commented Sep 6, 2023

Description

Issue #15074 (comment) shows that there are two bugs in the vounit formatte that produce output not compliant to the VOUnits standard. If fractions are used, the formatter adds a space around the slash, and for fractional power exponents the power sign (**) is omitted:

>>> import astropy.units as u
>>> (u.km/u.h).to_string(format="vounit", fraction=True)  # expected: 'km/h'
'km / h'
>>> (u.Hz**0.5).to_string(format="vounit")  # expected: 'Hz**(1/2)'
'Hz(1/2)'
>>> (u.Hz**-0.5).to_string(format="vounit", fraction=True)  # expected: '1/Hz**(1/2)'
'1 / Hz(1/2)'

This PR addresses both, and adds unit tests for them.

@github-actions
Copy link

github-actions bot commented Sep 6, 2023

Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • Is a milestone set? Milestone must be set but we cannot check for it on Actions; do not let the green checkmark fool you.
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

@olebole olebole added the Bug label Sep 6, 2023
@mhvk mhvk added this to the v5.3.3 milestone Sep 6, 2023
@mhvk mhvk added the 💤 backport-v5.3.x on-merge: backport to v5.3.x label Sep 6, 2023
Copy link
Contributor

@mhvk mhvk left a comment

Choose a reason for hiding this comment

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

Thanks! The code and tests look good! What is still needed is a changelog fragment.

Comment on lines 719 to 723
@pytest.mark.parametrize(
"fraction",
[True, "inline"],
)
Copy link
Member

Choose a reason for hiding this comment

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

This should fit on a single line. Is the trailing comma intentional?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure were it came from, as black had nothing to change here. And IMO trailing commas in this case are normal black format for multi-line parameter lists.

@olebole
Copy link
Member Author

olebole commented Sep 6, 2023

@mhvk Changelog entry is added.

Copy link
Contributor

@mhvk mhvk left a comment

Choose a reason for hiding this comment

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

Looks all good now!

@mhvk mhvk merged commit 68950c0 into astropy:main Sep 7, 2023
24 of 25 checks passed
meeseeksmachine pushed a commit to meeseeksmachine/astropy that referenced this pull request Sep 7, 2023
pllim added a commit that referenced this pull request Sep 7, 2023
…282-on-v5.3.x

Backport PR #15282 on branch v5.3.x (Fix vounit formatting of fractions and powers)
@olebole olebole deleted the vounit-formatter branch September 7, 2023 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug units 💤 backport-v5.3.x on-merge: backport to v5.3.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants