Skip to content

BUG: Adds newline after info() call on empty dataframe #45498

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 5 commits into from
Jan 22, 2022
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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/formats/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/io/formats/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def duplicate_columns_frame():


def test_info_empty():
# GH #45494
df = DataFrame()
buf = StringIO()
df.info(buf=buf)
Expand All @@ -37,7 +38,7 @@ def test_info_empty():
"""\
<class 'pandas.core.frame.DataFrame'>
Index: 0 entries
Empty DataFrame"""
Empty DataFrame\n"""
)
assert result == expected

Expand Down