Skip to content

Commit 4e3d691

Browse files
authored
BUG: Adds newline after info() call on empty dataframe (#45498)
1 parent 9e4c59b commit 4e3d691

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

doc/source/whatsnew/v1.5.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ MultiIndex
231231
I/O
232232
^^^
233233
- Bug in :meth:`DataFrame.to_stata` where no error is raised if the :class:`DataFrame` contains ``-np.inf`` (:issue:`45350`)
234-
-
234+
- 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`)
235235

236236
Period
237237
^^^^^^

pandas/io/formats/info.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ def _fill_empty_info(self) -> None:
812812
"""Add lines to the info table, pertaining to empty dataframe."""
813813
self.add_object_type_line()
814814
self.add_index_range_line()
815-
self._lines.append(f"Empty {type(self.data).__name__}")
815+
self._lines.append(f"Empty {type(self.data).__name__}\n")
816816

817817
@abstractmethod
818818
def _fill_non_empty_info(self) -> None:

pandas/tests/io/formats/test_info.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def duplicate_columns_frame():
2929

3030

3131
def test_info_empty():
32+
# GH #45494
3233
df = DataFrame()
3334
buf = StringIO()
3435
df.info(buf=buf)
@@ -37,7 +38,7 @@ def test_info_empty():
3738
"""\
3839
<class 'pandas.core.frame.DataFrame'>
3940
Index: 0 entries
40-
Empty DataFrame"""
41+
Empty DataFrame\n"""
4142
)
4243
assert result == expected
4344

0 commit comments

Comments
 (0)