-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG-17280 to_html follows display.precision for column numbers in notebooks #25914
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 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9040b98
BUG-17280 to_html follows display.precision for column numbers
JustinZhengBC 21d8273
applies to notebooks only
JustinZhengBC 8e0b7ee
fix whitespace
JustinZhengBC 87c183e
fix whitespace
JustinZhengBC f7d8086
move formatting to _get_columns_formatted_values function
JustinZhengBC 50aea27
use self.columns.format()
JustinZhengBC 3998835
Merge branch 'master' into BUG-17280
JustinZhengBC 4ea1932
add issue number
JustinZhengBC ebcc8f8
Merge branch 'BUG-17280' of https://github.com/justinzhengbc/pandas i…
JustinZhengBC 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 |
---|---|---|
|
@@ -633,3 +633,12 @@ def test_to_html_invalid_classes_type(classes): | |
|
||
with pytest.raises(TypeError, match=msg): | ||
df.to_html(classes=classes) | ||
|
||
|
||
def test_to_html_round_column_headers(): | ||
df = DataFrame([1], columns=[0.55555]) | ||
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. add the issue number |
||
with pd.option_context('display.precision', 3): | ||
html = df.to_html(notebook=False) | ||
notebook = df.to_html(notebook=True) | ||
assert "0.55555" in html | ||
assert "0.556" in notebook |
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.
does this really need to be in
__init__
, rather have this call a method in the base class which is overriden here, e.g.self.columns = self._get_columns_formatted_values()
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.
in #24651, i separated out the notebook functionality from
HTMLFormatter
intoNotebookFormatter
usingHTMLFormatter
as the base class. the base class ofHTMLFormatter
isTableFormatter
which is also the base class ofDataFrameFormatter
(used forto_string
andto _latex
) andLatexFormatter
.I envisaged that at some point in the development cycle it may become desirable to also create a
ToHTMLFormatter
usingHTMLFormatter
as the base.IMO
HTMLFormatter
andNotebookFormatter
are not the appropriate location for non-markup related formatting issues that are common across output-formatting methods. I think this issue is in that category and should ideally be inDataFrameFormatter
orTableFormatter
.However, if to close the open issue the fix is somewhere in
io/formats/html.py
, then i think a TODO to remove the code at a later date should be added.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 think I'm getting a bit confused here. Doesn't this mean that this is not an issue that is common across formatters? Because
to_html
should only check display preferences when used for display purposes in a notebook and not when generating HTML for a web page?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.
yeah. i can understand why your confused, there is a slight problem with the current class hierarchy. the workaround for
max_colwidth
was to usewith option_context
to ignore the display option forto_html
, see #24841There 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 think the ideal solution would be to have say a
use_display_options
attribute inDataFrameFormatter
and then inHTMLFormatter
we just haveself.fmt.use_display_options = False
and inNoteBookFormatter
we haveself.fmt.use_display_options = True
and then all the display formatting could be handled inio/formats/format.py
.But this is way outside the scope of this PR. So a
with option_context
work-around would be fine for now IMO.