From 3cd9698442ba9e3f2c721a5a2446544ad9ed65ee Mon Sep 17 00:00:00 2001 From: Benedikt Sauer Date: Wed, 19 Feb 2014 09:19:55 +0100 Subject: [PATCH] Remove the special case for empty dataframes in to_html. Fixes issue #6062. --- doc/source/release.rst | 1 + doc/source/v0.14.0.txt | 2 ++ pandas/core/format.py | 14 +++----------- pandas/tests/test_format.py | 9 +++++---- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/doc/source/release.rst b/doc/source/release.rst index 0e6924e4b0122..1aaed66d0daa5 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -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 diff --git a/doc/source/v0.14.0.txt b/doc/source/v0.14.0.txt index d773f3e7df799..e101cc1d1dd2b 100644 --- a/doc/source/v0.14.0.txt +++ b/doc/source/v0.14.0.txt @@ -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`) diff --git a/pandas/core/format.py b/pandas/core/format.py index 537fdc6cd0a27..7108be9fb0851 100644 --- a/pandas/core/format.py +++ b/pandas/core/format.py @@ -694,17 +694,9 @@ def write_result(self, buf): self.write('' % ' '.join(_classes), indent) - if len(frame.columns) == 0 or len(frame.index) == 0: - self.write('', 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('', 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('
', indent) if self.fmt.show_dimensions: diff --git a/pandas/tests/test_format.py b/pandas/tests/test_format.py index 5296be15f242e..efede49e7fa26 100644 --- a/pandas/tests/test_format.py +++ b/pandas/tests/test_format.py @@ -1588,11 +1588,12 @@ def test_to_html_with_classes(self): expected = dedent(""" - - - - + + + + +
Index([], dtype='object')Empty DataFrame