Skip to content

BUG: ValueError: buffer source array is read-only #37174

Closed
@dmitra79

Description

@dmitra79
  • I have checked that this issue has not already been reported.

  • [ X ] I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


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 "<stdin>", line 1, in <module>
  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

  • cython=0.29.14=py37he1b5a44_0
  • pandas=0.24.2=py37he6710b0_0
    Don't know if the isin() example would have thrown an error with that)

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
'''

Metadata

Metadata

Assignees

No one assigned

    Labels

    AlgosNon-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diffBug

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions