pitrou commented on code in PR #45818:
URL: https://github.com/apache/arrow/pull/45818#discussion_r2068900808
##########
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():
Review Comment:
I don't think you have to do all this by hand. `self.as_buffer()` already
gives you a [Python
buffer-compliant](https://docs.python.org/3/c-api/buffer.html) object, so you
can build on that.
Something like this:
```cython
def __getbuffer__(self, cp.Py_buffer* view, int flags):
buf = self.as_buffer()
if buf is None:
raise ValueError("Cannot export buffer from null Arrow Scalar")
return cp.PyObject_GetBuffer(buf, view, flags)
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]