Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions pandas/tests/strings/test_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,3 +818,33 @@ def test_decode_with_dtype_none():
result = ser.str.decode("utf-8", dtype=None)
expected = Series(["a", "b", "c"], dtype="str")
tm.assert_series_equal(result, expected)


def test_setitem_with_different_string_storage():
# GH#52987
# Test setitem with values from different string storage type
pytest.importorskip("pyarrow")

# Test Series[string[python]].__setitem__(Series[string[pyarrow]])
ser_python = Series(range(5), dtype="string[python]")
ser_pyarrow = ser_python.astype("string[pyarrow]")

ser_python[:2] = ser_pyarrow[:2]
expected = Series(["0", "1", "2", "3", "4"], dtype="string[python]")
tm.assert_series_equal(ser_python, expected)

# Test Series[string[pyarrow]].__setitem__(Series[string[python]])
ser_pyarrow = Series(range(5), dtype="string[pyarrow]")
ser_python = ser_pyarrow.astype("string[python]")

ser_pyarrow[:2] = ser_python[:2]
expected = Series(["0", "1", "2", "3", "4"], dtype="string[pyarrow]")
tm.assert_series_equal(ser_pyarrow, expected)

# Test with slice and missing values
ser_python = Series(["a", "b", None, "d", "e"], dtype="string[python]")
ser_pyarrow = Series(["X", "Y", None], dtype="string[pyarrow]")

ser_python[1:4] = ser_pyarrow
expected = Series(["a", "X", "Y", NA, "e"], dtype="string[python]")
tm.assert_series_equal(ser_python, expected)
Loading