MCPcopy Create free account
hub / github.com/apache/arrow / test_buffer

Function test_buffer

python/pyarrow/tests/interchange/test_interchange_spec.py:244–274  ·  view source on GitHub ↗
(int, use_batch)

Source from the content-addressed store, hash-verified

242)
243@pytest.mark.parametrize("use_batch", [False, True])
244def 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(

Callers

nothing calls this directly

Calls 7

to_batchesMethod · 0.80
__dataframe__Method · 0.80
get_columnMethod · 0.80
get_buffersMethod · 0.80
__dlpack_device__Method · 0.80
from_addressMethod · 0.80
arrayMethod · 0.45

Tested by

no test coverage detected