BUG: ValueError: buffer source array is read-only · Issue #37174 · pandas-dev/pandas (original) (raw)


This seems similar to: #31710
I am getting it in a dash application, so it's difficult to get an example from there.
However, isin() example from the above post also causes the error:

Code Sample, a copy-pastable example

import numpy as np # v1.16.4, then v1.18.1 import pandas as pd # v1.0.1

arr = np.array([1,2,3], dtype=np.int64) # works fine if I don't set the dtype!

arr.setflags(write=False) # make it read-only

df = pd.DataFrame({"col": [2,4,8]})

test = df.col.isin(arr) Traceback (most recent call last): File "", line 1, in File "/home/z0022z7b/anaconda3/envs/mindsynchro/lib/python3.8/site-packages/pandas/core/series.py", line 4685, in isin result = algorithms.isin(self, values) File "/home/z0022z7b/anaconda3/envs/mindsynchro/lib/python3.8/site-packages/pandas/core/algorithms.py", line 465, in isin return f(comps, values) File "pandas/_libs/hashtable_func_helper.pxi", line 566, in pandas._libs.hashtable.ismember_int64 File "stringsource", line 658, in View.MemoryView.memoryview_cwrapper File "stringsource", line 349, in View.MemoryView.memoryview.cinit ValueError: buffer source array is read-only

Problem description

The problem is this error. My application code worked fine before, but I had to set it up on a new machine with new pandas and cython a couple days ago, and ran into this.
(Previously I had

Output of pd.show_versions()

'''

INSTALLED VERSIONS

commit : db08276
python : 3.8.6.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-118-generic
Version : #119-Ubuntu SMP Tue Sep 8 12:30:01 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.1.3
numpy : 1.19.2
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.3
setuptools : 49.6.0.post20201009
Cython : 0.29.21
lxml.etree : 4.5.2
jinja2 : 2.11.2
IPython : 7.18.1
fsspec : 0.8.4
fastparquet : 0.4.1
matplotlib : 3.3.2
pyarrow : 0.17.1
scipy : 1.5.2
xarray : 0.16.1
numba : 0.51.2
'''