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

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

Merged
merged 2 commits into from Apr 19, 2023

Conversation

Telomelonia
Copy link
Contributor

@Telomelonia Telomelonia commented Feb 13, 2023

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

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

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

astropy/coordinates/angles.py Outdated Show resolved Hide resolved
docs/changes/coordinates/14379.bugfix.rst Outdated Show resolved Hide resolved
astropy/coordinates/tests/test_angles.py Show resolved Hide resolved
Copy link
Member

@eerovaher eerovaher left a comment

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
Copy link
Contributor

mhvk commented Feb 14, 2023

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
Contributor 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
Copy link
Contributor

mhvk commented Feb 15, 2023

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
Copy link
Contributor

mhvk commented Apr 18, 2023

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

@mhvk
Copy link
Contributor

mhvk commented Apr 18, 2023

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

@pllim
Copy link
Member

pllim commented Apr 18, 2023

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

@mhvk
Copy link
Contributor

mhvk commented Apr 18, 2023

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

@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
25 checks passed
@pllim
Copy link
Member

pllim commented Apr 19, 2023

Thanks, all!

@Telomelonia
Copy link
Contributor 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

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