Skip to content

ENH: Remove the hardcoded border=1 in the to_html dataframe export. #4578

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

Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ pandas 0.13
- A Series of dtype ``timedelta64[ns]`` can now be divided by another
``timedelta64[ns]`` object to yield a ``float64`` dtyped Series. This
is frequency conversion.
- Border is not anymore hardcoded when a Dataframe is exported to
HTML. (:issue:`4578`)

**API Changes**

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ def write_result(self, buf):
'not %s') % type(self.classes))
_classes.extend(self.classes)

self.write('<table border="1" class="%s">' % ' '.join(_classes),
self.write('<table class="%s">' % ' '.join(_classes),
Copy link
Contributor

Choose a reason for hiding this comment

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

What jreback means is to do the following right here

if get_option('notebook.style.border'):
    fmt = '<table border="%d" class="%%s"> ' % get_option('notebook.style.border')
else:
   fmt = '<table class="%s">'
 self.write(fmt % ' '.join(_classes)

And then somewhere in the file add:

border_ doc = """
: integer or string

Border width to be set via table border property
"""

config.register_option('notebook.style.border', 1, border_doc, None)

indent)

if len(frame.columns) == 0 or len(frame.index) == 0:
Expand Down
24 changes: 12 additions & 12 deletions pandas/tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def test_to_html_escaped(self):
'co>l2':{a: "<type 'str'>",
b: "<type 'str'>"}}
rs = pd.DataFrame(test_dict).to_html()
xp = """<table border="1" class="dataframe">
xp = """<table class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
Expand Down Expand Up @@ -419,7 +419,7 @@ def test_to_html_escape_disabled(self):
'co>l2': {a: "<b>bold</b>",
b: "<b>bold</b>"}}
rs = pd.DataFrame(test_dict).to_html(escape=False)
xp = """<table border="1" class="dataframe">
xp = """<table class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
Expand Down Expand Up @@ -451,7 +451,7 @@ def test_to_html_multiindex_sparsify_false_multi_sparse(self):

result = df.to_html()
expected = """\
<table border="1" class="dataframe">
<table class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
Expand Down Expand Up @@ -500,7 +500,7 @@ def test_to_html_multiindex_sparsify_false_multi_sparse(self):

result = df.to_html()
expected = """\
<table border="1" class="dataframe">
<table class="dataframe">
<thead>
<tr>
<th></th>
Expand Down Expand Up @@ -557,7 +557,7 @@ def test_to_html_multiindex_sparsify(self):
df = DataFrame([[0, 1], [2, 3], [4, 5], [6, 7]], index=index)

result = df.to_html()
expected = """<table border="1" class="dataframe">
expected = """<table class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
Expand Down Expand Up @@ -604,7 +604,7 @@ def test_to_html_multiindex_sparsify(self):

result = df.to_html()
expected = """\
<table border="1" class="dataframe">
<table class="dataframe">
<thead>
<tr>
<th></th>
Expand Down Expand Up @@ -659,7 +659,7 @@ def test_to_html_index_formatter(self):
f = lambda x: 'abcd'[x]
result = df.to_html(formatters={'__index__': f})
expected = """\
<table border="1" class="dataframe">
<table class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
Expand Down Expand Up @@ -1255,7 +1255,7 @@ def test_to_html_multiindex(self):
names=['CL0', 'CL1'])
df = pandas.DataFrame([list('abcd'), list('efgh')], columns=columns)
result = df.to_html(justify='left')
expected = ('<table border="1" class="dataframe">\n'
expected = ('<table class="dataframe">\n'
' <thead>\n'
' <tr>\n'
' <th>CL0</th>\n'
Expand Down Expand Up @@ -1295,7 +1295,7 @@ def test_to_html_multiindex(self):
df = pandas.DataFrame([list('abcd'), list('efgh')], columns=columns)

result = df.to_html(justify='right')
expected = ('<table border="1" class="dataframe">\n'
expected = ('<table class="dataframe">\n'
' <thead>\n'
' <tr>\n'
' <th></th>\n'
Expand Down Expand Up @@ -1338,7 +1338,7 @@ def test_to_html_justify(self):
'C': [223442, 0, 1]},
columns=['A', 'B', 'C'])
result = df.to_html(justify='left')
expected = ('<table border="1" class="dataframe">\n'
expected = ('<table class="dataframe">\n'
' <thead>\n'
' <tr style="text-align: left;">\n'
' <th></th>\n'
Expand Down Expand Up @@ -1372,7 +1372,7 @@ def test_to_html_justify(self):
self.assertEqual(result, expected)

result = df.to_html(justify='right')
expected = ('<table border="1" class="dataframe">\n'
expected = ('<table class="dataframe">\n'
' <thead>\n'
' <tr style="text-align: right;">\n'
' <th></th>\n'
Expand Down Expand Up @@ -1452,7 +1452,7 @@ def test_to_html_with_classes(self):
result = df.to_html(classes="sortable draggable")
expected = dedent("""

<table border="1" class="dataframe sortable draggable">
<table class="dataframe sortable draggable">
<tbody>
<tr>
<td>Index([], dtype=object)</td>
Expand Down