diff --git a/doc/source/whatsnew/v1.5.0.rst b/doc/source/whatsnew/v1.5.0.rst index 1ae76984484af..3a8bbf420da1a 100644 --- a/doc/source/whatsnew/v1.5.0.rst +++ b/doc/source/whatsnew/v1.5.0.rst @@ -227,7 +227,7 @@ MultiIndex I/O ^^^ - Bug in :meth:`DataFrame.to_stata` where no error is raised if the :class:`DataFrame` contains ``-np.inf`` (:issue:`45350`) -- +- Bug in :meth:`DataFrame.info` where a new line at the end of the output is omitted when called on an empty :class:`DataFrame` (:issue:`45494`) Period ^^^^^^ diff --git a/pandas/io/formats/info.py b/pandas/io/formats/info.py index 504b2d632860f..dbdb1b1b96984 100644 --- a/pandas/io/formats/info.py +++ b/pandas/io/formats/info.py @@ -812,7 +812,7 @@ def _fill_empty_info(self) -> None: """Add lines to the info table, pertaining to empty dataframe.""" self.add_object_type_line() self.add_index_range_line() - self._lines.append(f"Empty {type(self.data).__name__}") + self._lines.append(f"Empty {type(self.data).__name__}\n") @abstractmethod def _fill_non_empty_info(self) -> None: diff --git a/pandas/tests/io/formats/test_info.py b/pandas/tests/io/formats/test_info.py index 5522631d222e1..6bcf971e5bb05 100644 --- a/pandas/tests/io/formats/test_info.py +++ b/pandas/tests/io/formats/test_info.py @@ -29,6 +29,7 @@ def duplicate_columns_frame(): def test_info_empty(): + # GH #45494 df = DataFrame() buf = StringIO() df.info(buf=buf) @@ -37,7 +38,7 @@ def test_info_empty(): """\ Index: 0 entries - Empty DataFrame""" + Empty DataFrame\n""" ) assert result == expected