-
-
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
REGR: object column repr not respecting float format #40850
Conversation
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.
looks fine, ping on green.
doc/source/whatsnew/v1.2.4.rst
Outdated
@@ -20,7 +20,7 @@ Fixed regressions | |||
- Fixed regression in (in)equality comparison of ``pd.NaT`` with a non-datetimelike numpy array returning a scalar instead of an array (:issue:`40722`) | |||
- Fixed regression in :meth:`DataFrame.where` not returning a copy in the case of an all True condition (:issue:`39595`) | |||
- Fixed regression in :meth:`DataFrame.replace` raising ``IndexError`` when ``regex`` was a multi-key dictionary (:issue:`39338`) | |||
- | |||
- Fixed regression in repr of floats in an ``object`` column not respecting ``float_format`` (:issue:`40024`) |
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 that float_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 not to_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
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.
Thanks @mzeitlin11 lgtm
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 comment
The 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 comment
The 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
doc/source/whatsnew/v1.2.4.rst
Outdated
@@ -20,7 +20,7 @@ Fixed regressions | |||
- Fixed regression in (in)equality comparison of ``pd.NaT`` with a non-datetimelike numpy array returning a scalar instead of an array (:issue:`40722`) | |||
- Fixed regression in :meth:`DataFrame.where` not returning a copy in the case of an all True condition (:issue:`39595`) | |||
- Fixed regression in :meth:`DataFrame.replace` raising ``IndexError`` when ``regex`` was a multi-key dictionary (:issue:`39338`) | |||
- | |||
- Fixed regression in repr of floats in an ``object`` column not respecting ``float_format`` when printed in the console or outputted through :meth:`DataFrame.to_html` and :meth:`DataFrame.to_latex` (:issue:`40024`) |
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.
and also to_string?
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, have added reference to that 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.
Thanks @mzeitlin11
Thanks @mzeitlin11 |
@meeseeksdev backport 1.2.x |
…mat (#40875) Co-authored-by: Matthew Zeitlin <[email protected]>
This is a regression caused by #38759