Repository navigation
Added a feature which will allow the user to control space b/w value and unit - #14231
Telomelonia wants to merge 11 commits into
Conversation
|
The tests need updating. A new test to use the alternate option is also necessary. Also a change log is necessary (as you have noted in your checklist). Thanks! |
mhvk
left a comment
There was a problem hiding this comment.
Thanks for the PR, but I wonder why this is needed? Most journals insist that a space is used between a number and the unit. Also, while for simple units this might make sense, it does not generalize to composite units (which have spaces in between them).
Overall, my tendency would be to leave this for people to sort for themselves if they want it; generally .to_string(...).replace(' ', '') will be all that's needed.
So, not in favour; marking as "request changes" since if we were to go for adding this option, it definitely should have a different name.
|
Oops, I'm so sorry, I hadn't even realized that the issue here is to fix that angles do not have spaces between the number and the unit. Very silly of me; I should have read the issue. Now having done so, I agree with the comments there that the default should be to have the space, with the only exception being when one of the special symbols is used. My tendency would be not to even have an option for this. Anyway, now in favour as long as we change the default! |
| unit_string = unit_string[1:-1] | ||
| format_func = func | ||
| func = lambda x: format_func(x) + unit_string | ||
| # Add a space if no format(i.e unicode or latex) is given |
There was a problem hiding this comment.
I wonder if the whole else clause could simply leave it to Quantity.to_string() via
return super().to_string(unit=unit, precision=precision, format=format)
There was a problem hiding this comment.
Hmm nice, that will simplify the code ... let me review it again
947ad3a to
5e9730a
Compare
Added a space between value and unit and added a feature of old style if someone wants to use the old style no space string
5e9730a to
e559b02
Compare
|
@pllim |
|
pre-commit.ci autofix |
There was a problem hiding this comment.
A test need to be added with oldstyle=True to ensure it works as intended.
Please rename the change log fragment file from 14231.feature.rst to 14231.api.rst as suggested by reviewer. Change log text also need to elaborate what this oldstyle actually does and why it is needed now.
Needs to squash all commits into one before this is ready for merge too. To do that, please remember to pull in pre-commit autofix commit from GitHub back to your local checkout first. Feel free to ask if you are unsure how to do this part.
|
I think there is still one open question: as I commented above, I wonder if we even need the p.s. If we do go with an option, we should give it a better name (and default should definitely be off). |
|
Co-authored-by: P. L. Lim <[email protected]>
Co-authored-by: P. L. Lim <[email protected]>
|
pre-commit.ci autofix |
|
Re: #14231 (comment) @mhvk , I think that is a discussion for astropy-dev mailing list and/or dev telecon. I am going to turn this PR into draft until this discussion is resolved. |
|
Let's just ping the coordinate team - @eerovaher, @StuartLittlefair, @adrn, @eteq - on whether to make a space between a number and the unit the standard case (as it is for |
|
I agree with @mhvk that there is no need to make the "old style" option available as a keyword argument to Lines 45 to 52 in 24a4ee1 |
|
Just to sat that in response to @mhvk's ping, I have no strong opinion on this. The only real issue I can anticipate is if third-parties had based their unit tests on the string output from angles, in which case I don't have much sympathy... |
|
I thinking of making another PR to address this issue as just a bug where a space is required in the result in between value and unit. |
|
@Telomelonia - it might indeed be good to have 2 PRs to compare, though it also is fine to work with this one, Thanks for persisting!!! |
Description
I added a boolean feature
oldstyleinto_string(), giving flexibility to the user to have a space between value and unit.By default, space should be given in between whenever its possible.
NOTE-For some units like 34'20'' or 11h22m no space should be added whether the feature is set to
TrueorFalse.TODOs
This pull request is to address ...
Fixes #7455
Testing
Checklist for package maintainer(s)
This checklist is meant to remind the package maintainer(s) who will review this pull request of some common things to look for. This list is not exhaustive.
Extra CIlabel. Codestyle issues can be fixed by the bot.no-changelog-entry-neededlabel. If this is a manual backport, use theskip-changelog-checkslabel unless special changelog handling is necessary.astropy-botcheck might be missing; do not let the green checkmark fool you.backport-X.Y.xlabel(s) before merge.