Code Sample, a copy-pastable example if possible
arr = np.arange(10)
arr.setflags(write=False)
ser = pd.Series(arr, index=arr)
print ser.unique()
...
File "/usr/local/lib/python2.7/dist-packages/pandas/core/algorithms.py", line 364, in unique
uniques = table.unique(values)
File "pandas/_libs/hashtable_class_helper.pxi", line 973, in pandas._libs.hashtable.Int64HashTable.unique
File "stringsource", line 646, in View.MemoryView.memoryview_cwrapper
File "stringsource", line 347, in View.MemoryView.memoryview.__cinit__
ValueError: buffer source array is read-only
Problem description
For no good reason, unique tries to modify the input and fails if the input data is read only.
Perhaps should simply delegate to np.unique which does not modify the input.
Expected Output
Operation should not modify the input. Is rude to the caller and will doubtless lead to inexplicable concurrency issues.
Output of pd.show_versions()
Comment From: jschendel
This works on master for me, and I suspect it was fixed by #18825
In [2]: arr = np.arange(10)
In [3]: arr.setflags(write=False)
In [4]: ser = pd.Series(arr, index=arr)
In [5]: ser.unique()
Out[5]: array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=int64)
In [6]: pd.__version__
Out[6]: '0.23.0.dev0+98.g8acdf80'
Comment From: jreback
yep this is in 0.23.0
Comment From: jreback
@stuz5000 note that this is actually a bug in cython which pandas works around
Comment From: gabomgp
I'll put this here, delete if is inappropiate. But, the question is related with this bug:
https://stackoverflow.com/questions/49619588/how-to-prevent-bug-https-github-com-pandas-dev-pandas-issues-19195-with-dese