From b2c70c094dabf4822230a7d77d041108ef4dccf7 Mon Sep 17 00:00:00 2001 From: hippowm Date: Wed, 16 Jul 2025 03:20:31 -0700 Subject: [PATCH 1/4] add test for dtype argument in str.decode --- pandas/tests/strings/test_strings.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pandas/tests/strings/test_strings.py b/pandas/tests/strings/test_strings.py index 025f837982595..eec2569d45aea 100644 --- a/pandas/tests/strings/test_strings.py +++ b/pandas/tests/strings/test_strings.py @@ -11,6 +11,7 @@ Index, MultiIndex, Series, + set_option, ) import pandas._testing as tm from pandas.core.strings.accessor import StringMethods @@ -778,3 +779,12 @@ def test_series_str_decode(): result = Series([b"x", b"y"]).str.decode(encoding="UTF-8", errors="strict") expected = Series(["x", "y"], dtype="str") tm.assert_series_equal(result, expected) + + +def test_decode_with_dtype_none(): + # Ensure that future.infer_string is enabled + set_option("future.infer_string", True) + ser = Series([b"a", b"b", b"c"]) # Use byte strings + result = ser.str.decode("utf-8", dtype=None) + expected = Series(["a", "b", "c"], dtype="str") + tm.assert_series_equal(result, expected) From 6e8fb65ccf576c9f522eef21263c6fd5d89929ac Mon Sep 17 00:00:00 2001 From: hippowm Date: Wed, 16 Jul 2025 20:56:40 -0700 Subject: [PATCH 2/4] use option_context --- pandas/tests/strings/test_strings.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pandas/tests/strings/test_strings.py b/pandas/tests/strings/test_strings.py index eec2569d45aea..156fcb7dacd71 100644 --- a/pandas/tests/strings/test_strings.py +++ b/pandas/tests/strings/test_strings.py @@ -11,7 +11,7 @@ Index, MultiIndex, Series, - set_option, + option_context, ) import pandas._testing as tm from pandas.core.strings.accessor import StringMethods @@ -783,8 +783,8 @@ def test_series_str_decode(): def test_decode_with_dtype_none(): # Ensure that future.infer_string is enabled - set_option("future.infer_string", True) - ser = Series([b"a", b"b", b"c"]) # Use byte strings - result = ser.str.decode("utf-8", dtype=None) - expected = Series(["a", "b", "c"], dtype="str") - tm.assert_series_equal(result, expected) + with option_context("future.infer_string", True): + ser = Series([b"a", b"b", b"c"]) # Use byte strings + result = ser.str.decode("utf-8", dtype=None) + expected = Series(["a", "b", "c"], dtype="str") + tm.assert_series_equal(result, expected) From adc32b878a5bc4592a087cb48d640ede846bfba6 Mon Sep 17 00:00:00 2001 From: WhimsyHippo Date: Thu, 17 Jul 2025 11:29:01 -0700 Subject: [PATCH 3/4] remove comment Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> --- pandas/tests/strings/test_strings.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/tests/strings/test_strings.py b/pandas/tests/strings/test_strings.py index 156fcb7dacd71..eac579c2b1031 100644 --- a/pandas/tests/strings/test_strings.py +++ b/pandas/tests/strings/test_strings.py @@ -782,7 +782,6 @@ def test_series_str_decode(): def test_decode_with_dtype_none(): - # Ensure that future.infer_string is enabled with option_context("future.infer_string", True): ser = Series([b"a", b"b", b"c"]) # Use byte strings result = ser.str.decode("utf-8", dtype=None) From cceb9daf18b5053afb8369cf4a73329f679ee545 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Mon, 28 Jul 2025 10:23:51 -0700 Subject: [PATCH 4/4] Update pandas/tests/strings/test_strings.py --- pandas/tests/strings/test_strings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/strings/test_strings.py b/pandas/tests/strings/test_strings.py index eac579c2b1031..695eef06e3b9d 100644 --- a/pandas/tests/strings/test_strings.py +++ b/pandas/tests/strings/test_strings.py @@ -783,7 +783,7 @@ def test_series_str_decode(): def test_decode_with_dtype_none(): with option_context("future.infer_string", True): - ser = Series([b"a", b"b", b"c"]) # Use byte strings + ser = Series([b"a", b"b", b"c"]) result = ser.str.decode("utf-8", dtype=None) expected = Series(["a", "b", "c"], dtype="str") tm.assert_series_equal(result, expected)