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

CLN: io/formats/html.py: refactor #23818

Merged
merged 5 commits into from
Nov 27, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 2 additions & 6 deletions pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,12 +730,8 @@ def to_html(self, classes=None, notebook=False, border=None):
.. versionadded:: 0.19.0
"""
from pandas.io.formats.html import HTMLFormatter
html_renderer = HTMLFormatter(self, classes=classes,
max_rows=self.max_rows,
max_cols=self.max_cols,
notebook=notebook,
border=border,
table_id=self.table_id)
html_renderer = HTMLFormatter(self, classes=classes, notebook=notebook,
border=border, table_id=self.table_id)
if hasattr(self.buf, 'write'):
html_renderer.write_result(self.buf)
elif isinstance(self.buf, compat.string_types):
Expand Down
24 changes: 8 additions & 16 deletions pandas/io/formats/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class HTMLFormatter(TableFormatter):

indent_delta = 2

def __init__(self, formatter, classes=None, max_rows=None, max_cols=None,
notebook=False, border=None, table_id=None):
def __init__(self, formatter, classes=None, notebook=False, border=None,
table_id=None):
self.fmt = formatter
self.classes = classes

Expand All @@ -35,12 +35,8 @@ def __init__(self, formatter, classes=None, max_rows=None, max_cols=None,
self.elements = []
self.bold_rows = self.fmt.kwds.get('bold_rows', False)
self.escape = self.fmt.kwds.get('escape', True)

self.max_rows = max_rows or len(self.fmt.frame)
self.max_cols = max_cols or len(self.fmt.columns)
self.show_dimensions = self.fmt.show_dimensions
self.is_truncated = (self.max_rows < len(self.fmt.frame) or
self.max_cols < len(self.fmt.columns))
self.is_truncated = self.fmt.is_truncated
gfyoung marked this conversation as resolved.
Show resolved Hide resolved
self.notebook = notebook
if border is None:
border = get_option('display.html.border')
Expand Down Expand Up @@ -301,12 +297,9 @@ def _write_header(self, indent):
if all((self.fmt.has_index_names,
self.fmt.index,
self.fmt.show_index_names)):
row = ([x if x is not None else ''
for x in self.frame.index.names] +
[''] * min(len(self.columns), self.max_cols))
if truncate_h:
ins_col = row_levels + self.fmt.tr_col_num
row.insert(ins_col, '')
ncols = len(self.fmt.tr_frame.columns)
row = ([x if x is not None else '' for x in self.frame.index.names]
+ [''] * (ncols + (1 if truncate_h else 0)))
self.write_tr(row, indent, self.indent_delta, header=True)

indent -= self.indent_delta
Expand All @@ -318,9 +311,8 @@ def _write_body(self, indent):
self.write('<tbody>', indent)
indent += self.indent_delta

fmt_values = {}
for i in range(min(len(self.columns), self.max_cols)):
fmt_values[i] = self.fmt._format_col(i)
ncols = len(self.fmt.tr_frame.columns)
gfyoung marked this conversation as resolved.
Show resolved Hide resolved
fmt_values = {i: self.fmt._format_col(i) for i in range(ncols)}

# write values
if self.fmt.index and isinstance(self.frame.index, ABCMultiIndex):
Expand Down