Skip to content

Commit dcbbc59

Browse files
committed
Merge pull request pandas-dev#6405 from filmor/patch-1
Remove the special case for empty dataframes.
2 parents 03743af + 3cd9698 commit dcbbc59

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
@@ -74,6 +74,7 @@ API Changes
7474
- ``dtypes`` and ``ftypes`` now return a series with ``dtype=object`` on empty containers (:issue:`5740`)
7575
- ``df.to_csv`` will now return a string of the CSV data if neither a target path nor a buffer is provided
7676
(:issue:`6061`)
77+
- ``df.to_html`` will now print out the header of an empty dataframe (:issue:`6062`)
7778
- The ``interpolate`` ``downcast`` keyword default has been changed from ``infer`` to
7879
``None``. This is to preseve the original dtype unless explicitly requested otherwise (:issue:`6290`).
7980
- 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
@@ -42,6 +42,8 @@ These are out-of-bounds selections
4242

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

pandas/core/format.py

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

715-
if len(frame.columns) == 0 or len(frame.index) == 0:
716-
self.write('<tbody>', indent + self.indent_delta)
717-
self.write_tr([repr(frame.index),
718-
'Empty %s' % type(frame).__name__],
719-
indent + (2 * self.indent_delta),
720-
self.indent_delta)
721-
self.write('</tbody>', indent + self.indent_delta)
722-
else:
723-
indent += self.indent_delta
724-
indent = self._write_header(indent)
725-
indent = self._write_body(indent)
715+
indent += self.indent_delta
716+
indent = self._write_header(indent)
717+
indent = self._write_body(indent)
726718

727719
self.write('</table>', indent)
728720
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)