-
-
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 all 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<table border="1" class="dataframe"> | ||
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. Don't have a very strong opinion atm but wondering if we want dedicated files for tests this small. Could maybe include HTML as part of the test or alternately just test for the existence of the appropriate format in the result or the expression. This doesn't need to be addressed in this PR but just bringing up as a general discussion point |
||
<thead> | ||
<tr style="text-align: right;"> | ||
<th></th> | ||
<th>x</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<th>0</th> | ||
<td>0.200</td> | ||
</tr> | ||
</tbody> | ||
</table> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<table border="1" class="dataframe"> | ||
<thead> | ||
<tr style="text-align: right;"> | ||
<th></th> | ||
<th>x</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<th>0</th> | ||
<td>100</td> | ||
</tr> | ||
</tbody> | ||
</table> |
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]}) | ||
|
||
|
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.