-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
Changes from 3 commits
bebe152
bac5ee5
e554d07
2069f3d
a7ddf80
5fa9ff8
bda9961
a9666bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -974,6 +974,7 @@ def __init__(self, *args, **kwargs): | |
# float_format is expected to be a string | ||
# formatter should be used to pass a function | ||
if self.float_format is not None and self.formatter is None: | ||
self.fixed_width = False | ||
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. can you see if u can change 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. is this possible? 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. 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 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 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. |
||
if callable(self.float_format): | ||
self.formatter = self.float_format | ||
self.float_format = None | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1328,6 +1328,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]}) | ||
|
||
|
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.
use a ',' rather than 'and'