Skip to content

Clean up formatting of units in unicode and console formats - #14413

Merged
pllim merged 5 commits into
astropy:mainfrom
mhvk:units-format-unicode-console-strings
Feb 18, 2023
Merged

pllim merged 5 commits into
astropy:mainfrom
mhvk:units-format-unicode-console-strings

Conversation

@mhvk

@mhvk mhvk commented Feb 18, 2023

Copy link
Copy Markdown
Contributor

Description

This pull request is to address that in console and unicode format, spaces were not always done properly: for units typeset as a fraction there was a space in front of the unit even without a scale factor, while for units set on a single line, there was no space between the scale factor and the unit.

(Plus some small bits of refactoring while I was at it.)

Fixes #14409

@mhvk mhvk added this to the v5.3 milestone Feb 18, 2023
@mhvk
mhvk requested a review from olebole February 18, 2023 01:17
@github-actions

Copy link
Copy Markdown
Contributor

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 "When to rebase and squash commits".
  • 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 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.

I am fine with it; just one minor nitpicky comment!

Comment thread astropy/units/format/console.py Outdated
s = ""
else:
s = cls.format_exponential_notation(unit.scale)
s = cls.format_exponential_notation(unit.scale) + " "

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.

To be nitpicky here: for a scale-only unit this adds a trailing space:

>>> u.Unit(10).to_string('unicode')
'10 '

Probably one again use a "parts" list and " ".join(parts) at the end, as in generic.py (but just with 1-2 parts)?

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.

Good catch! the parts use is a bit tricky given the possible multiple lines so I just added the space only when needed. It turned out for latex the same mistake was made, so I corrected that while I was at it.

@mhvk
mhvk force-pushed the units-format-unicode-console-strings branch from 31327b9 to 5f40d64 Compare February 18, 2023 15:09
@mhvk

mhvk commented Feb 18, 2023

Copy link
Copy Markdown
Contributor Author

@nstarman - this PR is already approved by @olebole (minus a change I implemented), but his approval is not (yet!) sufficient for merging. Could you have a look?

@pllim
pllim requested a review from nstarman February 18, 2023 16:46

@pllim pllim 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.

I am approving by proxy but I will give nstarman a chance to review.

Thanks!

@nstarman nstarman 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.

All the test files shows the changes are good. I didn't catch any more of @olebole'a subtle bugs... LGTM! Thanks @mhvk

@pllim
pllim merged commit 5770efb into astropy:main Feb 18, 2023
@mhvk
mhvk deleted the units-format-unicode-console-strings branch February 18, 2023 19:15
mhvk pushed a commit to mhvk/astropy that referenced this pull request Feb 19, 2023
…le-strings

Clean up formatting of units in unicode and console formats
davidgegiya added a commit to davidgegiya/agent-orchestrator that referenced this pull request Nov 8, 2026
…s include an extraneous space

Pin 34d79ea59b3ba25820dfe7fc9782e9014826e8b0 and its regression selectors for reproducible runs.

Source: astropy/astropy#14413
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.

Unicode and console unit representations sometimes include an extraneous space

4 participants