iloc breaks on read-only dataframe · Issue #10043 · pandas-dev/pandas (original) (raw)

This is picking up #9928 again. I don't know if the behavior is expected, but it is a bit odd to me. Maybe I'm doing something wrong, I'm not that familiar with the pandas internals.

We call df.iloc[indices] and that breaks with a read-only dataframe. I feel that it shouldn't though, as it is not writing.

Minimal reproducing example:

import pandas as pd import numpy as np array = np.eye(10) array.setflags(write=False)

X = pd.DataFrame(array) X.iloc[[1, 2, 3]]

ValueError buffer source array is read-only

Is there a way to slice the rows of the dataframe in another way that doesn't need a writeable array?