-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
BUG: Fix float formatting when a string is passed as float_format arg #22308
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bebe152
BUG: Fix float formatting when a string is passed as float_format arg
tomneep bac5ee5
Put new float_format test cases into separate test
tomneep e554d07
Add whatsnew entry
tomneep 2069f3d
Comma to and in whatsnew entry
tomneep a7ddf80
Rebase
tomneep 5fa9ff8
Modify whatsnew entry
tomneep bda9961
Adding tests to test_to_html and test_to_latex
tomneep a9666bd
Add new line to end of test_to_html.py
tomneep File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1359,6 +1359,18 @@ def test_to_string_float_formatting(self): | |
'1 2.512000e-01') | ||
assert df_s == expected | ||
|
||
def test_to_string_float_format_no_fixed_width(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you would need to add tests for to_latex and to_html in the appropriate files |
||
|
||
# GH 21625 | ||
df = DataFrame({'x': [0.19999]}) | ||
expected = ' x\n0 0.200' | ||
assert df.to_string(float_format='%.3f') == expected | ||
|
||
# GH 22270 | ||
df = DataFrame({'x': [100.0]}) | ||
expected = ' x\n0 100' | ||
assert df.to_string(float_format='%.0f') == expected | ||
|
||
def test_to_string_small_float_values(self): | ||
df = DataFrame({'a': [1.5, 1e-17, -5.5e-7]}) | ||
|
||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you see if u can change
fixed_width
to a cached property instead of setting it (need to remove from the signature as well)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a good chance I'm not understanding the comment, but I'm not sure we can set this as a cached property (using the
cache_readonly
decorator?) since it is set in the base class. As I say I might be missing something...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can set it in each of the subclasses. I just don't think we actually need this. try doing this as a property first to see if it works.