Skip to content

Remove the special case for empty dataframes. #6405

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

Merged
merged 1 commit into from
Mar 14, 2014
Merged
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
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ API Changes
- ``dtypes`` and ``ftypes`` now return a series with ``dtype=object`` on empty containers (:issue:`5740`)
- ``df.to_csv`` will now return a string of the CSV data if neither a target path nor a buffer is provided
(:issue:`6061`)
- ``df.to_html`` will now print out the header of an empty dataframe (:issue:`6062`)
- The ``interpolate`` ``downcast`` keyword default has been changed from ``infer`` to
``None``. This is to preseve the original dtype unless explicitly requested otherwise (:issue:`6290`).
- allow a Series to utilize index methods depending on its index type, e.g. ``Series.year`` is now defined
Expand Down
2 changes: 2 additions & 0 deletions doc/source/v0.14.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ These are out-of-bounds selections

- The ``DataFrame.interpolate()`` ``downcast`` keyword default has been changed from ``infer`` to
``None``. This is to preseve the original dtype unless explicitly requested otherwise (:issue:`6290`).
- When converting a dataframe to HTML it used to return `Empty DataFrame`. This special case has
been removed, instead a header with the column names is returned (:issue:`6062`).
- allow a Series to utilize index methods depending on its index type, e.g. ``Series.year`` is now defined
for a Series with a ``DatetimeIndex`` or a ``PeriodIndex``; trying this on a non-supported Index type will
now raise a ``TypeError``. (:issue:`4551`, :issue:`4056`, :issue:`5519`)
Expand Down
14 changes: 3 additions & 11 deletions pandas/core/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,17 +694,9 @@ def write_result(self, buf):
self.write('<table border="1" class="%s">' % ' '.join(_classes),
indent)

if len(frame.columns) == 0 or len(frame.index) == 0:
self.write('<tbody>', indent + self.indent_delta)
self.write_tr([repr(frame.index),
'Empty %s' % type(frame).__name__],
indent + (2 * self.indent_delta),
self.indent_delta)
self.write('</tbody>', indent + self.indent_delta)
else:
indent += self.indent_delta
indent = self._write_header(indent)
indent = self._write_body(indent)
indent += self.indent_delta
indent = self._write_header(indent)
indent = self._write_body(indent)

self.write('</table>', indent)
if self.fmt.show_dimensions:
Expand Down
9 changes: 5 additions & 4 deletions pandas/tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -1588,11 +1588,12 @@ def test_to_html_with_classes(self):
expected = dedent("""

<table border="1" class="dataframe sortable draggable">
<tbody>
<tr>
<td>Index([], dtype='object')</td>
<td>Empty DataFrame</td>
<thead>
<tr style="text-align: right;">
<th></th>
</tr>
</thead>
<tbody>
</tbody>
</table>

Expand Down