Data in the buffer is guaranteed to be contiguous in memory. Note that there is no dtype attribute present, a buffer can be thought of as simply a block of memory. However, if the column that the buffer is attached to has a dtype that's supported by DLPack and ``__dlpack__`` is
| 35 | |
| 36 | |
| 37 | class _PyArrowBuffer: |
| 38 | """ |
| 39 | Data in the buffer is guaranteed to be contiguous in memory. |
| 40 | |
| 41 | Note that there is no dtype attribute present, a buffer can be thought of |
| 42 | as simply a block of memory. However, if the column that the buffer is |
| 43 | attached to has a dtype that's supported by DLPack and ``__dlpack__`` is |
| 44 | implemented, then that dtype information will be contained in the return |
| 45 | value from ``__dlpack__``. |
| 46 | |
| 47 | This distinction is useful to support both data exchange via DLPack on a |
| 48 | buffer and (b) dtypes like variable-length strings which do not have a |
| 49 | fixed number of bytes per element. |
| 50 | """ |
| 51 | |
| 52 | def __init__(self, x: pa.Buffer, allow_copy: bool = True) -> None: |
| 53 | """ |
| 54 | Handle PyArrow Buffers. |
| 55 | """ |
| 56 | self._x = x |
| 57 | |
| 58 | @property |
| 59 | def bufsize(self) -> int: |
| 60 | """ |
| 61 | Buffer size in bytes. |
| 62 | """ |
| 63 | return self._x.size |
| 64 | |
| 65 | @property |
| 66 | def ptr(self) -> int: |
| 67 | """ |
| 68 | Pointer to start of the buffer as an integer. |
| 69 | """ |
| 70 | return self._x.address |
| 71 | |
| 72 | def __dlpack__(self): |
| 73 | """ |
| 74 | Produce DLPack capsule (see array API standard). |
| 75 | |
| 76 | Raises: |
| 77 | - TypeError : if the buffer contains unsupported dtypes. |
| 78 | - NotImplementedError : if DLPack support is not implemented |
| 79 | |
| 80 | Useful to have to connect to array libraries. Support optional because |
| 81 | it's not completely trivial to implement for a Python-only library. |
| 82 | """ |
| 83 | raise NotImplementedError("__dlpack__") |
| 84 | |
| 85 | def __dlpack_device__(self) -> tuple[DlpackDeviceType, int | None]: |
| 86 | """ |
| 87 | Device type and device ID for where the data in the buffer resides. |
| 88 | Uses device type codes matching DLPack. |
| 89 | Note: must be implemented even if ``__dlpack__`` is not. |
| 90 | """ |
| 91 | if self._x.is_cpu: |
| 92 | return (DlpackDeviceType.CPU, None) |
| 93 | else: |
| 94 | raise NotImplementedError("__dlpack_device__") |
no outgoing calls
no test coverage detected