Skip to content

Commit 3cd9698

Browse files
committed
Remove the special case for empty dataframes in to_html.
Fixes issue pandas-dev#6062.
1 parent a265c5c commit 3cd9698

File tree

4 files changed

+11
-15
lines changed

4 files changed

+11
-15
lines changed

doc/source/release.rst

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ API Changes
7373
- ``dtypes`` and ``ftypes`` now return a series with ``dtype=object`` on empty containers (:issue:`5740`)
7474
- ``df.to_csv`` will now return a string of the CSV data if neither a target path nor a buffer is provided
7575
(:issue:`6061`)
76+
- ``df.to_html`` will now print out the header of an empty dataframe (:issue:`6062`)
7677
- The ``interpolate`` ``downcast`` keyword default has been changed from ``infer`` to
7778
``None``. This is to preseve the original dtype unless explicitly requested otherwise (:issue:`6290`).
7879
- allow a Series to utilize index methods depending on its index type, e.g. ``Series.year`` is now defined

doc/source/v0.14.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ These are out-of-bounds selections
4141

4242
- The ``DataFrame.interpolate()`` ``downcast`` keyword default has been changed from ``infer`` to
4343
``None``. This is to preseve the original dtype unless explicitly requested otherwise (:issue:`6290`).
44+
- When converting a dataframe to HTML it used to return `Empty DataFrame`. This special case has
45+
been removed, instead a header with the column names is returned (:issue:`6062`).
4446
- allow a Series to utilize index methods depending on its index type, e.g. ``Series.year`` is now defined
4547
for a Series with a ``DatetimeIndex`` or a ``PeriodIndex``; trying this on a non-supported Index type will
4648
now raise a ``TypeError``. (:issue:`4551`, :issue:`4056`, :issue:`5519`)

pandas/core/format.py

+3-11
Original file line numberDiff line numberDiff line change
@@ -694,17 +694,9 @@ def write_result(self, buf):
694694
self.write('<table border="1" class="%s">' % ' '.join(_classes),
695695
indent)
696696

697-
if len(frame.columns) == 0 or len(frame.index) == 0:
698-
self.write('<tbody>', indent + self.indent_delta)
699-
self.write_tr([repr(frame.index),
700-
'Empty %s' % type(frame).__name__],
701-
indent + (2 * self.indent_delta),
702-
self.indent_delta)
703-
self.write('</tbody>', indent + self.indent_delta)
704-
else:
705-
indent += self.indent_delta
706-
indent = self._write_header(indent)
707-
indent = self._write_body(indent)
697+
indent += self.indent_delta
698+
indent = self._write_header(indent)
699+
indent = self._write_body(indent)
708700

709701
self.write('</table>', indent)
710702
if self.fmt.show_dimensions:

pandas/tests/test_format.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1588,11 +1588,12 @@ def test_to_html_with_classes(self):
15881588
expected = dedent("""
15891589
15901590
<table border="1" class="dataframe sortable draggable">
1591-
<tbody>
1592-
<tr>
1593-
<td>Index([], dtype='object')</td>
1594-
<td>Empty DataFrame</td>
1591+
<thead>
1592+
<tr style="text-align: right;">
1593+
<th></th>
15951594
</tr>
1595+
</thead>
1596+
<tbody>
15961597
</tbody>
15971598
</table>
15981599

0 commit comments

Comments
 (0)