BUG: avoid StringArray.setitem to mutate the value being set as side-effect by jorisvandenbossche · Pull Request #51299 · pandas-dev/pandas (original) (raw)
Encountered this while working on #51082, and this can be done as independent fix.
In [5]: arr = pd.array(["a", "b", "c"], dtype="string")
In [6]: value = np.array(["A", None])
In [7]: arr[[0, 1]] = value
In [8]: value
Out[8]: array(['A', <NA>], dtype=object) # <-- value got mutated !!
I think in general the value that is being set should never be mutated during the setitem operation.