WillAyd commented on code in PR #450:
URL: https://github.com/apache/arrow-nanoarrow/pull/450#discussion_r1586775118
##########
python/src/nanoarrow/_lib.pyx:
##########
@@ -1815,6 +1815,51 @@ cdef class CBufferView:
else:
return self._iter_dispatch(offset, length)
+ def unpack_bits_into(self, dest, offset=0, length=None, dest_offset=0):
+ if self._data_type != NANOARROW_TYPE_BOOL:
+ raise ValueError("Can't unpack non-boolean buffer")
+
+ if length is None:
+ length = self.n_elements
+
+ if offset < 0 or length < 0 or (offset + length) > self.n_elements:
+ raise IndexError(
+ f"offset {offset} and length {length} do not describe a valid
slice "
+ f"of buffer with {self.n_elements} elements"
+ )
+
+ cdef Py_buffer buffer
+ PyObject_GetBuffer(dest, &buffer, PyBUF_WRITABLE |
PyBUF_ANY_CONTIGUOUS)
+ if buffer.itemsize != 1:
+ PyBuffer_Release(&buffer)
+ raise ValueError("Destination buffer has itemsize != 1")
+
+ if buffer.len < (dest_offset + length):
Review Comment:
Maybe worth also checking that `dest_offset` is non-negative? I think you'd
get UB if a user decides to do something like `unpack_bits_into(..., len(dest)
+ 1, -1)` (not that they should...)
--
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]