Skip to content

Commit 31942c8

Browse files
author
Wang Haoxiang
authored
TST: Add regression tests for setitem with different string storage (… (#63009)
Co-authored-by: wdyy20041223 <2795352227@qq,com>
1 parent 88c276a commit 31942c8

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

pandas/tests/strings/test_strings.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,3 +818,33 @@ def test_decode_with_dtype_none():
818818
result = ser.str.decode("utf-8", dtype=None)
819819
expected = Series(["a", "b", "c"], dtype="str")
820820
tm.assert_series_equal(result, expected)
821+
822+
823+
def test_setitem_with_different_string_storage():
824+
# GH#52987
825+
# Test setitem with values from different string storage type
826+
pytest.importorskip("pyarrow")
827+
828+
# Test Series[string[python]].__setitem__(Series[string[pyarrow]])
829+
ser_python = Series(range(5), dtype="string[python]")
830+
ser_pyarrow = ser_python.astype("string[pyarrow]")
831+
832+
ser_python[:2] = ser_pyarrow[:2]
833+
expected = Series(["0", "1", "2", "3", "4"], dtype="string[python]")
834+
tm.assert_series_equal(ser_python, expected)
835+
836+
# Test Series[string[pyarrow]].__setitem__(Series[string[python]])
837+
ser_pyarrow = Series(range(5), dtype="string[pyarrow]")
838+
ser_python = ser_pyarrow.astype("string[python]")
839+
840+
ser_pyarrow[:2] = ser_python[:2]
841+
expected = Series(["0", "1", "2", "3", "4"], dtype="string[pyarrow]")
842+
tm.assert_series_equal(ser_pyarrow, expected)
843+
844+
# Test with slice and missing values
845+
ser_python = Series(["a", "b", None, "d", "e"], dtype="string[python]")
846+
ser_pyarrow = Series(["X", "Y", None], dtype="string[pyarrow]")
847+
848+
ser_python[1:4] = ser_pyarrow
849+
expected = Series(["a", "X", "Y", NA, "e"], dtype="string[python]")
850+
tm.assert_series_equal(ser_python, expected)

0 commit comments

Comments
 (0)