Skip to content

Windowing fails on read-only arrays #27766

Closed
@kernc

Description

@kernc

Code Sample, a copy-pastable example if possible

>>> arr = np.array([1, 3, np.nan, 3, 5])
>>> arr.setflags(write=False)
>>> pd.Series(arr).rolling(2).mean().values
---------------------------------------------------------------------------
ValueError: assignment destination is read-only

Expected Output

>>> pd.Series(arr).rolling(2).mean().values
array([nan,  2., nan, nan,  4.])

Problem description

#27391 (comment) missed a copy call before writing into array, which is user's data and which may be read-only.

Output of pd.show_versions()

pandas 0.25.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugWindowrolling, ewma, expanding

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions