[ https://issues.apache.org/jira/browse/ARROW-3228?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16612892#comment-16612892 ]
Wes McKinney edited comment on ARROW-3228 at 9/13/18 12:25 AM: --------------------------------------------------------------- Apparently somewhere a mutability flag isn't being respected. Wasn't obvious at a glance where the problem lies, see: * https://github.com/apache/arrow/blob/master/cpp/src/arrow/python/common.cc#L61 * https://github.com/apache/arrow/blob/master/python/pyarrow/io.pxi#L831 was (Author: wesmckinn): Apparently somewhere a mutability flag isn't being respected. What's obvious at a glance where the problem lies, see: * https://github.com/apache/arrow/blob/master/cpp/src/arrow/python/common.cc#L61 * https://github.com/apache/arrow/blob/master/python/pyarrow/io.pxi#L831 > [Python] Immutability of bytes is ignored > ----------------------------------------- > > Key: ARROW-3228 > URL: https://issues.apache.org/jira/browse/ARROW-3228 > Project: Apache Arrow > Issue Type: Bug > Components: Python > Reporter: Pearu Peterson > Priority: Major > Fix For: 0.11.0 > > > Creating a pyarrow.Buffer from Python bytes allows in-place changes of > immutable Python strings: > {code:java} > >>> import pyarrow as pa > >>> import numpy as np > >>> a = b'123456' > >>> a[0] = 77 # bytes are immutable, so TypeError is expected > TypeError: 'bytes' object does not support item assignment > >>> b = pa.py_buffer(a) # but with pyarrow bytes can be changed in-place > >>> arr = np.frombuffer(b, dtype=np.uint8) > >>> arr[0] = 66 # change 'a' in-place, would expect error > >>> a > b'B23456' > >>> hash(a) > -4581532003987476523 > >>> arr[0] = 77 > >>> a > b'M23456' > >>> hash(a) # hash value stays constant while changing 'a' > -4581532003987476523{code} > {{Notice that numpy.frombuffer respects immutability of bytes:}} > {{}} > {code:java} > >>> arr2 = np.frombuffer(a, dtype=np.uint8) > >>> arr2 > array([77, 50, 51, 52, 53, 54], dtype=uint8) > >>> arr2[0] = 88 # expecting error > ValueError: assignment destination is read-only{code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)