Skip to content

Bug fix of no space in the result of to_string. - #14379

Merged
pllim merged 2 commits into
astropy:mainfrom
Telomelonia:bug_val_space_unit
Apr 19, 2023
Merged

pllim merged 2 commits into
astropy:mainfrom
Telomelonia:bug_val_space_unit

Conversation

@Telomelonia

@Telomelonia Telomelonia commented Feb 13, 2023 •

Copy link
Copy Markdown
Member

Description

As mentioned in the issue, in the result of the to_string() function, there is no space between value and unit.So, I added a space between value and unit.

This pull request is to address ...

Fixes #7455

Close #14231

TODOS

  • space in LaTex format
  • fix for format = generic and unicode cases.
  • centralize the bug fix on the unit rather than the format.

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

@Telomelonia

Copy link
Copy Markdown
Member Author

@pllim
As discussed in #14231 I have made the issue fix as in bug fix rather than a feature request

@pllim pllim added this to the v5.3 milestone Feb 13, 2023
@pllim pllim added Bug API change PRs and issues that change an existing API, possibly requiring a deprecation period labels Feb 13, 2023
@pllim
pllim requested a review from mhvk February 13, 2023 20:55

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@Telomelonia - thanks for this! Some small nitpicky comments only. With those, this will be all set.

Comment thread astropy/coordinates/angles.py Resolved

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

With the changes this pull request is proposing the following works as it should:

>>> from astropy.coordinates import Angle
>>> Angle(5, unit="rad").to_string()
'5 rad'

But the following still produce a string without a space (it would be good to add a unit test analogous to one of these):

>>> Angle(5, unit="rad").to_string(format="unicode")
'5rad'
>>> Angle(5, unit="rad").to_string(format="generic")
'5rad'

It would seem that a space should not be added between the value and the unit if the format is "latex" or "latex_inline", or if the output is sexagesimal.

@mhvk

mhvk commented Feb 14, 2023

Copy link
Copy Markdown
Contributor

Oops, indeed, this is more of a partial fix than I had realized! I think in principle there should be a space also for latex, etc. In #14231, I had suggested to use super() for the non-sexagesimal case, but a quick try caused more breakage than I had thought would be the case. Also Quantity.to_string() does not support unicode (see new issue #14386) and arguably does latex wrong in typesetting the degree symbol with a space in between it and the value (new issue #14385).

One option here may be to just keep it simple and focus on the generic format only -- i.e., only update this PR to also allow format='generic'.

@Telomelonia

Copy link
Copy Markdown
Member Author

Oops, indeed, this is more of a partial fix than I had realized! I think in principle there should be a space also for latex, etc. In #14231, I had suggested to use super() for the non-sexagesimal case, but a quick try caused more breakage than I had thought would be the case. Also Quantity.to_string() does not support unicode (see new issue #14386) and arguably does latex wrong in typesetting the degree symbol with a space in between it and the value (new issue #14385).

One option here may be to just keep it simple and focus on the generic format only -- i.e., only update this PR to also allow format='generic'.

I think one way is to include every format possible where space is required, since few units don't require space like 32'48'' so there is too much if and else ... another possible way is to take the output from the function and check whether space should be given or not and if space is required then add 1 space else pass
The another task is to insert the space in the Latex part

@mhvk

mhvk commented Feb 15, 2023

Copy link
Copy Markdown
Contributor

My sense is still that apart from sexagesimal, this should all be handled by Quantity.to_string(). It may not be that tricky if we require that the latex and unicode entries for unit formats include whether a space is needed -- may need to edit things like Å and Ω -- or simply special-case the few that do not.

My sense, though, is not to let that stand in the way of doing the smaller change here, which solves things mostly.

@mhvk
mhvk force-pushed the bug_val_space_unit branch 2 times, most recently from 198c064 to a865798 Compare April 18, 2023 19:36
@mhvk

mhvk commented Apr 18, 2023

Copy link
Copy Markdown
Contributor

@Telomelonia - I squashed your commits and added an extra one that also adds a space for other formats. I think this way it is ready to go in!

@eerovaher - would you mind having another look? I think your comment is now addressed.

@pllim
pllim requested a review from eerovaher April 18, 2023 20:13
@mhvk
mhvk force-pushed the bug_val_space_unit branch from a865798 to 51bdf2d Compare April 18, 2023 20:34
@mhvk

mhvk commented Apr 18, 2023

Copy link
Copy Markdown
Contributor

Hopefully now got the visualization.wcsaxis bugs - should have tested locally with matplotlib installed...

@pllim

pllim commented Apr 18, 2023

Copy link
Copy Markdown
Member

Are the "TODO"s in original post above still relevant?

@mhvk

mhvk commented Apr 18, 2023

Copy link
Copy Markdown
Contributor

@pllim - I think they're basically done with my additional commit, so I ticked them.

@mhvk
mhvk force-pushed the bug_val_space_unit branch from 51bdf2d to 4c12086 Compare April 18, 2023 21:27
@mhvk
mhvk dismissed eerovaher’s stale review April 18, 2023 21:28

Requested changes have been implemented

@pllim
pllim merged commit c748299 into astropy:main Apr 19, 2023
@pllim

pllim commented Apr 19, 2023

Copy link
Copy Markdown
Member

Thanks, all!

@Telomelonia

Copy link
Copy Markdown
Member Author

@Telomelonia - I squashed your commits and added an extra one that also adds a space for other formats. I think this way it is ready to go in!

Thank you all for assisting me

davidgegiya added a commit to davidgegiya/agent-orchestrator that referenced this pull request Nov 8, 2026
Pin 01c96c8cf1289c25172d538e1309f89cac88d41c and its regression selectors for reproducible runs.

Source: astropy/astropy#14379
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API change PRs and issues that change an existing API, possibly requiring a deprecation period Bug coordinates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Space between value and unit

5 participants