diff --git a/pandas/io/formats/info.py b/pandas/io/formats/info.py index 89b5e45dbb3a2..dac523898092a 100644 --- a/pandas/io/formats/info.py +++ b/pandas/io/formats/info.py @@ -1096,7 +1096,7 @@ def headers(self) -> Sequence[str]: def _gen_rows_without_counts(self) -> Iterator[Sequence[str]]: """Iterator with string representation of body data without counts.""" - yield from self._gen_dtypes() + yield from ([dtype] for dtype in self._gen_dtypes()) def _gen_rows_with_counts(self) -> Iterator[Sequence[str]]: """Iterator with string representation of body data with counts.""" diff --git a/pandas/tests/series/methods/test_info.py b/pandas/tests/series/methods/test_info.py index 88f2cf384fc79..c1fee2b2ee648 100644 --- a/pandas/tests/series/methods/test_info.py +++ b/pandas/tests/series/methods/test_info.py @@ -190,3 +190,23 @@ def test_info_memory_usage_bug_on_multiindex(): # high upper bound diff = unstacked.memory_usage(deep=True).sum() - s.memory_usage(deep=True) assert diff < 2000 + + +def test_info_show_counts_false(): + s = Series([1]) + buf = StringIO() + s.info(buf=buf, show_counts=False) + result = buf.getvalue() + memory_bytes = float(s.memory_usage()) + expected = textwrap.dedent( + f"""\ + + RangeIndex: 1 entries, 0 to 0 + Series name: None + Dtype + ----- + int64 + dtypes: int64(1) + memory usage: {memory_bytes} bytes""" + ) + assert result.strip() == expected.strip()