**Breaking**: Figure.text: Fix typesetting of integers when mixed with floating-point values#3493
Merged
**Breaking**: Figure.text: Fix typesetting of integers when mixed with floating-point values#3493
Conversation
Contributor
Summary of changed imagesThis is an auto-generated report of images that have changed on the DVC remote
Image diff(s)Report last updated at commit 8864945 |
michaelgrund
approved these changes
Oct 9, 2024
weiji14
approved these changes
Oct 9, 2024
Member
weiji14
left a comment
There was a problem hiding this comment.
Mark as breaking? Ideally, users would have figured out to use text=["1", "2.0", "3.14", "4."] instead of passing in integers, if they wanted a specific number of decimal points printed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description of proposed changes
Currently,
Figure.textallows passing a list of non-string values into thetextparameter, e.g.,text=[1, 2, 3.0, 4.123, 5.000]. Internally, these non-string values are converted to an array of strings:pygmt/pygmt/src/text.py
Line 237 in 5cf7f6a
Instead of
np.atleast_1d(text).astype(str), we can also usenp.atleast_1d(np.asarray(text, dtype=str)). The former convertstextinto a numpy array (float64 in this case) first and then converts it to str dtype; the latter convertstextinto str dtype directly.Below are their differences:
The latter is faster (3.8 μs vs 4.57 μs) and the resulting array is smaller (20 bytes vs 128 bytes per element).
Also please pay attention to the different string representations. For an integer
1, the former will typeset1.0while the latter will typeset1. I think we can declare it as aFigure.textfor incorrectly typesetting integers when mixed with floating-point numbers.This PR adopts the latter one to fix the bug. An incorrect baseline image is also updated.