AlenkaF commented on code in PR #45818: URL: https://github.com/apache/arrow/pull/45818#discussion_r2065785844
########## python/pyarrow/scalar.pxi: ########## @@ -847,6 +882,33 @@ cdef class BinaryScalar(Scalar): buffer = self.as_buffer() return None if buffer is None else buffer.to_pybytes() + def __bytes__(self): + return (self.as_py()) + + def __getbuffer__(self, cp.Py_buffer* buffer, int flags): + cdef Buffer buf = self.as_buffer() + + if buf.buffer.get().is_mutable(): + buffer.readonly = 0 + else: + if flags & cp.PyBUF_WRITABLE: + raise BufferError("Writable buffer requested but Arrow " + "buffer was not mutable") + buffer.readonly = 1 + buffer.buf = <char *>buf.buffer.get().data() + buffer.len = buf.size + if buffer.buf == NULL: + assert buffer.len == 0 + buffer.buf = cp.PyBytes_AS_STRING(b"") Review Comment: I was looking into whether it's possible to construct a scalar with a `NULL` address, and I couldn’t find a way to do it—so either it’s not possible or it’s just very difficult :) Given that, I think your existing test for `None` scalar is appropriate. It would also be good to add a test for an empty string (`b''` and/or `''`). With those in place, we should be able to remove this part of the code: ```suggestion ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org