(int, use_batch)
| 242 | ) |
| 243 | @pytest.mark.parametrize("use_batch", [False, True]) |
| 244 | def test_buffer(int, use_batch): |
| 245 | arr = [0, 1, -1] |
| 246 | table = pa.table({"a": pa.array(arr, type=int)}) |
| 247 | if use_batch: |
| 248 | table = table.to_batches()[0] |
| 249 | df = table.__dataframe__() |
| 250 | col = df.get_column(0) |
| 251 | buf = col.get_buffers() |
| 252 | |
| 253 | dataBuf, dataDtype = buf["data"] |
| 254 | |
| 255 | assert dataBuf.bufsize > 0 |
| 256 | assert dataBuf.ptr != 0 |
| 257 | device, _ = dataBuf.__dlpack_device__() |
| 258 | |
| 259 | # 0 = DtypeKind.INT |
| 260 | # see DtypeKind class in column.py |
| 261 | assert dataDtype[0] == 0 |
| 262 | |
| 263 | if device == 1: # CPU-only as we're going to directly read memory here |
| 264 | bitwidth = dataDtype[1] |
| 265 | ctype = { |
| 266 | 8: ctypes.c_int8, |
| 267 | 16: ctypes.c_int16, |
| 268 | 32: ctypes.c_int32, |
| 269 | 64: ctypes.c_int64, |
| 270 | }[bitwidth] |
| 271 | |
| 272 | for idx, truth in enumerate(arr): |
| 273 | val = ctype.from_address(dataBuf.ptr + idx * (bitwidth // 8)).value |
| 274 | assert val == truth, f"Buffer at index {idx} mismatch" |
| 275 | |
| 276 | |
| 277 | @pytest.mark.parametrize( |
nothing calls this directly
no test coverage detected