[ 
https://issues.apache.org/jira/browse/ARROW-2155?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16364750#comment-16364750
 ] 

ASF GitHub Bot commented on ARROW-2155:
---------------------------------------

wesm commented on a change in pull request #1608: ARROW-2155: [Python] 
frombuffer() should respect mutability of argument (alternative solution)
URL: https://github.com/apache/arrow/pull/1608#discussion_r168303091
 
 

 ##########
 File path: cpp/src/arrow/python/common.cc
 ##########
 @@ -47,22 +48,37 @@ MemoryPool* get_memory_pool() {
 // ----------------------------------------------------------------------
 // PyBuffer
 
-PyBuffer::PyBuffer(PyObject* obj) : Buffer(nullptr, 0), obj_(nullptr) {
-  if (PyObject_CheckBuffer(obj)) {
-    obj_ = PyMemoryView_FromObject(obj);
-    Py_buffer* buffer = PyMemoryView_GET_BUFFER(obj_);
-    data_ = reinterpret_cast<const uint8_t*>(buffer->buf);
-    size_ = buffer->len;
-    capacity_ = buffer->len;
-    is_mutable_ = false;
+PyBuffer::PyBuffer() : Buffer(nullptr, 0) {}
+
+PyBuffer::PyBuffer(PyObject* obj) : Buffer(nullptr, 0) {
+  // Cannot propagate error upwards
+  (void)Init(obj);
 
 Review comment:
   This suggests we should make the ctors private and add a static alternative 
constructor `Status PyBuffer::FromPyObject(PyObject* obj, 
std::shared_ptr<Buffer>* out)` or something. This can be declared as 
`@staticmethod` in Cython

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> [Python] pa.frombuffer(bytearray) returns immutable Buffer
> ----------------------------------------------------------
>
>                 Key: ARROW-2155
>                 URL: https://issues.apache.org/jira/browse/ARROW-2155
>             Project: Apache Arrow
>          Issue Type: Improvement
>          Components: Python
>    Affects Versions: 0.8.0
>            Reporter: Antoine Pitrou
>            Assignee: Antoine Pitrou
>            Priority: Minor
>              Labels: pull-request-available
>             Fix For: 0.9.0
>
>
> I'd expect it to return a mutable buffer:
> {code:python}
> >>> pa.frombuffer(bytearray(10)).is_mutable
> False
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to