Skip to content

Commit 59a977b

Browse files
authored
BUG: Fix ValueError in Series.info(show_counts=False) (#62699)
1 parent 641ebf4 commit 59a977b

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

pandas/io/formats/info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ def headers(self) -> Sequence[str]:
10961096

10971097
def _gen_rows_without_counts(self) -> Iterator[Sequence[str]]:
10981098
"""Iterator with string representation of body data without counts."""
1099-
yield from self._gen_dtypes()
1099+
yield from ([dtype] for dtype in self._gen_dtypes())
11001100

11011101
def _gen_rows_with_counts(self) -> Iterator[Sequence[str]]:
11021102
"""Iterator with string representation of body data with counts."""

pandas/tests/series/methods/test_info.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,23 @@ def test_info_memory_usage_bug_on_multiindex():
190190
# high upper bound
191191
diff = unstacked.memory_usage(deep=True).sum() - s.memory_usage(deep=True)
192192
assert diff < 2000
193+
194+
195+
def test_info_show_counts_false():
196+
s = Series([1])
197+
buf = StringIO()
198+
s.info(buf=buf, show_counts=False)
199+
result = buf.getvalue()
200+
memory_bytes = float(s.memory_usage())
201+
expected = textwrap.dedent(
202+
f"""\
203+
<class 'pandas.Series'>
204+
RangeIndex: 1 entries, 0 to 0
205+
Series name: None
206+
Dtype
207+
-----
208+
int64
209+
dtypes: int64(1)
210+
memory usage: {memory_bytes} bytes"""
211+
)
212+
assert result.strip() == expected.strip()

0 commit comments

Comments
 (0)