Skip to content
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

Make DataFrame.to_html output full content #24841

Merged
merged 15 commits into from
Mar 3, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.24.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,7 @@ I/O
- Bug in :func:`DataFrame.to_html()` with ``index_names=False`` displaying index name (:issue:`22747`)
- Bug in :func:`DataFrame.to_html()` with ``header=False`` not displaying row index names (:issue:`23788`)
- Bug in :func:`DataFrame.to_html()` with ``sparsify=False`` that caused it to raise ``TypeError`` (:issue:`22887`)
- Bug in :func:`DataFrame.to_html()` where values were truncated using display options instead of displaying the full content (:issue:`17004`)
- Bug in :func:`DataFrame.to_string()` that broke column alignment when ``index=False`` and width of first column's values is greater than the width of first column's header (:issue:`16839`, :issue:`13032`)
- Bug in :func:`DataFrame.to_string()` that caused representations of :class:`DataFrame` to not take up the whole window (:issue:`22984`)
- Bug in :func:`DataFrame.to_csv` where a single level MultiIndex incorrectly wrote a tuple. Now just the value of the index is written (:issue:`19589`).
Expand Down
17 changes: 17 additions & 0 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,3 +675,20 @@ def tick_classes(request):
normalize=st.booleans(),
startingMonth=st.integers(min_value=1, max_value=12)
))

lorem_ipsum_text = (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can just define this in the function

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or just declare it in test_to_html. That seems easier to follow.

"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod"
" tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim"
" veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex"
" ea commodo consequat. Duis aute irure dolor in reprehenderit in"
" voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur"
" sint occaecat cupidatat non proident, sunt in culpa qui officia"
" deserunt mollit anim id est laborum.")


@pytest.fixture(scope='session')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to explicitly state scope? Assumed this to be session given location but maybe have that wrong

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the scope parameter of the fixture is the scope for which this fixture is shared. the default is to execute the fixture function and all of the dependent fixtures for each parametrized run of each test.
the session scope here just means that the fixture function is only executed once and reused each time. here the fixture setup is trivial so specifying the scope probably doesn't achieve anything.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless there is a value add I would remove

def lorem_ipsum():
"""
Fixture for Lorem ipsum placeholder text.
"""
return lorem_ipsum_text
13 changes: 11 additions & 2 deletions pandas/io/formats/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from pandas.core.dtypes.generic import ABCMultiIndex

from pandas import compat
from pandas import compat, option_context
import pandas.core.common as com
from pandas.core.config import get_option

Expand Down Expand Up @@ -320,9 +320,15 @@ def _write_header(self, indent):

self.write('</thead>', indent)

def _get_formatted_values(self):
jreback marked this conversation as resolved.
Show resolved Hide resolved
with option_context('display.max_colwidth', 999999):
WillAyd marked this conversation as resolved.
Show resolved Hide resolved
fmt_values = {i: self.fmt._format_col(i)
for i in range(self.ncols)}
return fmt_values

def _write_body(self, indent):
self.write('<tbody>', indent)
fmt_values = {i: self.fmt._format_col(i) for i in range(self.ncols)}
fmt_values = self._get_formatted_values()

# write values
if self.fmt.index and isinstance(self.frame.index, ABCMultiIndex):
Expand Down Expand Up @@ -486,6 +492,9 @@ class NotebookFormatter(HTMLFormatter):
DataFrame._repr_html_() and DataFrame.to_html(notebook=True)
"""

def _get_formatted_values(self):
return {i: self.fmt._format_col(i) for i in range(self.ncols)}

def write_style(self):
# We use the "scoped" attribute here so that the desired
# style properties for the data frame are not then applied
Expand Down
19 changes: 19 additions & 0 deletions pandas/tests/io/formats/test_to_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,3 +600,22 @@ def test_to_html_render_links(render_links, expected, datapath):
result = df.to_html(render_links=render_links)
expected = expected_html(datapath, expected)
assert result == expected


@pytest.mark.parametrize('max_colwidth', [10, 20, 50, 100])
def test_display_max_colwidth(lorem_ipsum, max_colwidth):
# see gh-17004
df = DataFrame([lorem_ipsum])
with pd.option_context('display.max_colwidth', max_colwidth):
result = df._repr_html_()
expected = lorem_ipsum[:max_colwidth - 4] + '...'
assert expected in result


@pytest.mark.parametrize('max_colwidth', [10, 20, 50, 100])
def test_ignore_display_max_colwidth(lorem_ipsum, max_colwidth):
# see gh-17004
df = DataFrame([lorem_ipsum])
with pd.option_context('display.max_colwidth', max_colwidth):
result = df.to_html()
assert lorem_ipsum in result