From f4eb0f2ab76ed87db93e9b714c6c2478e0220490 Mon Sep 17 00:00:00 2001 From: Nithurshen Date: Wed, 15 Oct 2025 14:30:08 +0530 Subject: [PATCH 1/9] FIX: Prevent ValueError in Series.info when show_counts=False --- pandas/io/formats/info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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.""" From 78646a0b5cebce9cdabfc7613c6b3213a4c890ea Mon Sep 17 00:00:00 2001 From: Nithurshen Date: Wed, 15 Oct 2025 14:41:13 +0530 Subject: [PATCH 2/9] DOC: Add whatsnew entry for Series.info bug fix --- doc/source/whatsnew/v3.0.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 0b7135b2d109d..8a263c6285c7b 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -1096,6 +1096,7 @@ I/O - Bug in :meth:`set_option` where setting the pandas option ``display.html.use_mathjax`` to ``False`` has no effect (:issue:`59884`) - Bug in :meth:`to_csv` where ``quotechar``` is not escaped when ``escapechar`` is not None (:issue:`61407`) - Bug in :meth:`to_excel` where :class:`MultiIndex` columns would be merged to a single row when ``merge_cells=False`` is passed (:issue:`60274`) +- Bug in :meth:`~pandas.Series.info` where calling with ``show_counts=False`` raised a :exc:`ValueError` (:issue:`62590`) Period ^^^^^^ From 35a39cf33727c807b5c6dc1a3cf834ddebba63ae Mon Sep 17 00:00:00 2001 From: Nithurshen Date: Wed, 15 Oct 2025 19:59:32 +0530 Subject: [PATCH 3/9] DOC: remove whatsnew entry for Series.info bug fix --- doc/source/whatsnew/v3.0.0.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 8a263c6285c7b..0b7135b2d109d 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -1096,7 +1096,6 @@ I/O - Bug in :meth:`set_option` where setting the pandas option ``display.html.use_mathjax`` to ``False`` has no effect (:issue:`59884`) - Bug in :meth:`to_csv` where ``quotechar``` is not escaped when ``escapechar`` is not None (:issue:`61407`) - Bug in :meth:`to_excel` where :class:`MultiIndex` columns would be merged to a single row when ``merge_cells=False`` is passed (:issue:`60274`) -- Bug in :meth:`~pandas.Series.info` where calling with ``show_counts=False`` raised a :exc:`ValueError` (:issue:`62590`) Period ^^^^^^ From 2d62a3b9e9143a9e12c269d1ef68d70c4717d1d1 Mon Sep 17 00:00:00 2001 From: Nithurshen Date: Wed, 15 Oct 2025 20:35:07 +0530 Subject: [PATCH 4/9] TST: Add regression test for Series.info with show_counts=False --- pandas/tests/series/methods/test_info.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pandas/tests/series/methods/test_info.py b/pandas/tests/series/methods/test_info.py index 88f2cf384fc79..12becadda6433 100644 --- a/pandas/tests/series/methods/test_info.py +++ b/pandas/tests/series/methods/test_info.py @@ -190,3 +190,13 @@ 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(): + # GH#62590 + s = Series([1, 2, None]) + buf = StringIO() + s.info(buf=buf, show_counts=False) + result = buf.getvalue() + assert "Non-Null Count" not in result + assert "" in result + assert "Dtype" in result From a4439bee86ec658cd87b6fbb01b495b766130280 Mon Sep 17 00:00:00 2001 From: Nithurshen Date: Wed, 15 Oct 2025 20:41:12 +0530 Subject: [PATCH 5/9] style: Format code with ruff --- pandas/tests/frame/test_query_eval.py | 20 +++++--------------- pandas/tests/series/methods/test_info.py | 1 + 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/pandas/tests/frame/test_query_eval.py b/pandas/tests/frame/test_query_eval.py index b599be5d042fe..b31e8529b238b 100644 --- a/pandas/tests/frame/test_query_eval.py +++ b/pandas/tests/frame/test_query_eval.py @@ -160,21 +160,13 @@ def test_query_empty_string(self): df.query("") def test_query_duplicate_column_name(self, engine, parser): - df = DataFrame( - { - "A": range(3), - "B": range(3), - "C": range(3) - } - ).rename(columns={"B": "A"}) + df = DataFrame({"A": range(3), "B": range(3), "C": range(3)}).rename( + columns={"B": "A"} + ) res = df.query("C == 1", engine=engine, parser=parser) - expect = DataFrame( - [[1, 1, 1]], - columns=["A", "A", "C"], - index=[1] - ) + expect = DataFrame([[1, 1, 1]], columns=["A", "A", "C"], index=[1]) tm.assert_frame_equal(res, expect) @@ -1140,9 +1132,7 @@ def test_query_with_nested_special_character(self, parser, engine): [">=", operator.ge], ], ) - def test_query_lex_compare_strings( - self, parser, engine, op, func - ): + def test_query_lex_compare_strings(self, parser, engine, op, func): a = Series(np.random.default_rng(2).choice(list("abcde"), 20)) b = Series(np.arange(a.size)) df = DataFrame({"X": a, "Y": b}) diff --git a/pandas/tests/series/methods/test_info.py b/pandas/tests/series/methods/test_info.py index 12becadda6433..9caaaf732b057 100644 --- a/pandas/tests/series/methods/test_info.py +++ b/pandas/tests/series/methods/test_info.py @@ -191,6 +191,7 @@ def test_info_memory_usage_bug_on_multiindex(): diff = unstacked.memory_usage(deep=True).sum() - s.memory_usage(deep=True) assert diff < 2000 + def test_info_show_counts_false(): # GH#62590 s = Series([1, 2, None]) From 316dd9be9c265b3217f9562b0d1ea359775a579d Mon Sep 17 00:00:00 2001 From: Nithurshen Date: Wed, 15 Oct 2025 21:21:07 +0530 Subject: [PATCH 6/9] TST: Using universal format for test_info_show_counts_false() --- pandas/tests/series/methods/test_info.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/pandas/tests/series/methods/test_info.py b/pandas/tests/series/methods/test_info.py index 9caaaf732b057..44926fc16ed84 100644 --- a/pandas/tests/series/methods/test_info.py +++ b/pandas/tests/series/methods/test_info.py @@ -193,11 +193,20 @@ def test_info_memory_usage_bug_on_multiindex(): def test_info_show_counts_false(): - # GH#62590 - s = Series([1, 2, None]) + s = Series([1]) buf = StringIO() s.info(buf=buf, show_counts=False) result = buf.getvalue() - assert "Non-Null Count" not in result - assert "" in result - assert "Dtype" in result + 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() \ No newline at end of file From 44a98a533a4a598f52460827cd410c36714df934 Mon Sep 17 00:00:00 2001 From: Nithurshen Date: Wed, 15 Oct 2025 21:23:09 +0530 Subject: [PATCH 7/9] style: using ruff format for test_info.py --- pandas/tests/series/methods/test_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/series/methods/test_info.py b/pandas/tests/series/methods/test_info.py index 44926fc16ed84..c1fee2b2ee648 100644 --- a/pandas/tests/series/methods/test_info.py +++ b/pandas/tests/series/methods/test_info.py @@ -209,4 +209,4 @@ def test_info_show_counts_false(): dtypes: int64(1) memory usage: {memory_bytes} bytes""" ) - assert result.strip() == expected.strip() \ No newline at end of file + assert result.strip() == expected.strip() From 161acb94b9f8d37ae09e41b0dc8b10350fae1a94 Mon Sep 17 00:00:00 2001 From: Nithurshen Date: Thu, 16 Oct 2025 06:57:17 +0530 Subject: [PATCH 8/9] style: fixing unintentional modifications in test_query_eval.py --- pandas/tests/frame/test_query_eval.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pandas/tests/frame/test_query_eval.py b/pandas/tests/frame/test_query_eval.py index b31e8529b238b..5bcb08152deae 100644 --- a/pandas/tests/frame/test_query_eval.py +++ b/pandas/tests/frame/test_query_eval.py @@ -160,13 +160,21 @@ def test_query_empty_string(self): df.query("") def test_query_duplicate_column_name(self, engine, parser): - df = DataFrame({"A": range(3), "B": range(3), "C": range(3)}).rename( - columns={"B": "A"} - ) + df = DataFrame( + { + "A": range(3), + "B": range(3), + "C": range(3) + } + ).rename(columns={"B": "A"}) res = df.query("C == 1", engine=engine, parser=parser) - expect = DataFrame([[1, 1, 1]], columns=["A", "A", "C"], index=[1]) + expect = DataFrame( + [[1, 1, 1]], + columns=["A", "A", "C"], + index=[1] + ) tm.assert_frame_equal(res, expect) From 03c5534afb8c805e137b5f4e2d1b9d4ad4d5280c Mon Sep 17 00:00:00 2001 From: Nithurshen Date: Thu, 16 Oct 2025 06:59:21 +0530 Subject: [PATCH 9/9] style: fixing unintentional modifications in test_query_eval.py --- pandas/tests/frame/test_query_eval.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/tests/frame/test_query_eval.py b/pandas/tests/frame/test_query_eval.py index 5bcb08152deae..b599be5d042fe 100644 --- a/pandas/tests/frame/test_query_eval.py +++ b/pandas/tests/frame/test_query_eval.py @@ -1140,7 +1140,9 @@ def test_query_with_nested_special_character(self, parser, engine): [">=", operator.ge], ], ) - def test_query_lex_compare_strings(self, parser, engine, op, func): + def test_query_lex_compare_strings( + self, parser, engine, op, func + ): a = Series(np.random.default_rng(2).choice(list("abcde"), 20)) b = Series(np.arange(a.size)) df = DataFrame({"X": a, "Y": b})