Closed
Description
Code Sample, a copy-pastable example if possible
>>> index = pd.date_range('2020', 'now', freq='1h')
>>> arr = np.zeros_like(index)
>>> arr.setflags(write=False)
>>> pd.Series(arr, index=index).resample('1d').agg('last')
-------------------------------------------------------------------------
~/pandas/pandas/_libs/groupby.pyx in pandas._libs.groupby.group_last()
~/pandas/pandas/_libs/groupby.cpython-37m-x86_64-linux-gnu.so in View.MemoryView.memoryview_cwrapper()
~/pandas/pandas/_libs/groupby.cpython-37m-x86_64-linux-gnu.so in View.MemoryView.memoryview.__cinit__()
ValueError: buffer source array is read-only
Problem description
Groupby fails on some read-only buffers (I couldn't quickly reproduce it with .groupby()
itself, sorry).
The prime solution would be to add const
specifier to the input values
here (and related entries):
pandas/pandas/_libs/groupby.pyx
Line 853 in 0b6debf
if it were not for Cython's non-support of const fused types (cython/cython#1772), resolved in (cython/cython#3118), but despite miniscule change only scheduled for release in Cython 3.0. I guess wait until then.
Expected Output
Resampling/groupby works with read-only arrays.
Output of pd.show_versions()
pandas 1.1.0.dev0+361.gf0b00f887
cython 0.29.14