-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
REGR: object column repr not respecting float format #40850
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
236df37
58a4bc4
52639d7
cf5c528
7c9b13d
e06e55d
aaec9a3
2c82615
d051b00
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 |
---|---|---|
|
@@ -883,3 +883,29 @@ def test_to_html_na_rep_and_float_format(na_rep): | |
</tbody> | ||
</table>""" | ||
assert result == expected | ||
|
||
|
||
def test_to_html_float_format_object_col(): | ||
# GH#40024 | ||
df = DataFrame(data={"x": [1000.0, "test"]}) | ||
result = df.to_html(float_format=lambda x: f"{x:,.0f}") | ||
expected = """<table border="1" class="dataframe"> | ||
<thead> | ||
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. the expected html should be in a file, but I see #36690 slipped through #36690 (comment) so OK to leave as follow-up 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. ok, thanks that's good to know. Will make a follow-up fixing that |
||
<tr style="text-align: right;"> | ||
<th></th> | ||
<th>x</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<th>0</th> | ||
<td>1,000</td> | ||
</tr> | ||
<tr> | ||
<th>1</th> | ||
<td>test</td> | ||
</tr> | ||
</tbody> | ||
</table>""" | ||
|
||
assert result == expected |
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 only for to_html? or more generally?
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.
I guess also console repr (so mention these 2). doesn't affect, csv for example, right?
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.
Yep it affects to_html and console repr.
In theory we might want this to affect
to_csv
, but this doesn't change behavior right now because formatting is handled based on column dtype, such thatfloat_format
doesn't get used for object dtype columns even if some values in that column are floats.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.
Also affects
to_latex
, but notto_json
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.
ok pls list those and add a test for to_latex if you can
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.
Have updated whatsnew and added to_latex test