Skip to content

API/BUG: PandasArray __setitem__ can change underlying buffer #28150

Closed
@jbrockmendel

Description

@jbrockmendel

Discussed briefly in #28119, the ndarray backing a PandasArray can be swapped out by setitem, which can have surprising behavior for views

arr = pd.array([1, 2, 3])
view1 = arr.view()
view2 = arr[:]
view3 = np.asarray(arr)

arr[0] = 9
assert view1[0] == 9
assert view2[0] == 9 
assert view3[0] == 9

arr[1] = 2.5
view1[-1] = 5
assert arr[-1] == 5  # FAIL

Metadata

Metadata

Assignees

No one assigned

    Labels

    ExtensionArrayExtending pandas with custom dtypes or arrays.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions