Skip to content

BUG: avoid StringArray.__setitem__ to mutate the value being set as side-effect #51299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

jorisvandenbossche
Copy link
Member

@jorisvandenbossche jorisvandenbossche commented Feb 10, 2023

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.

@jorisvandenbossche jorisvandenbossche added Bug Strings String extension data type and string data labels Feb 10, 2023
@jorisvandenbossche jorisvandenbossche added this to the 2.0 milestone Feb 10, 2023
Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I imagine this fix should have a whatsnew note?

@mroeschke mroeschke merged commit ddceb8e into pandas-dev:main Feb 11, 2023
@mroeschke
Copy link
Member

Thanks @jorisvandenbossche

@jorisvandenbossche jorisvandenbossche deleted the bug-string-array-setitem-mutate-value branch February 11, 2023 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Strings String extension data type and string data
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants