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

Function test_buffers_nested

python/pyarrow/tests/test_array.py:3026–3058  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3024
3025
3026def test_buffers_nested():
3027 a = pa.array([[1, 2], None, [3, None, 4, 5]], type=pa.list_(pa.int64()))
3028 buffers = a.buffers()
3029 assert len(buffers) == 4
3030 # The parent buffers
3031 null_bitmap = buffers[0].to_pybytes()
3032 assert bytearray(null_bitmap)[0] == 0b00000101
3033 offsets = buffers[1].to_pybytes()
3034 assert struct.unpack('4i', offsets) == (0, 2, 2, 6)
3035 # The child buffers
3036 null_bitmap = buffers[2].to_pybytes()
3037 assert bytearray(null_bitmap)[0] == 0b00110111
3038 values = buffers[3].to_pybytes()
3039 assert struct.unpack('qqq8xqq', values) == (1, 2, 3, 4, 5)
3040
3041 a = pa.array([(42, None), None, (None, 43)],
3042 type=pa.struct([pa.field('a', pa.int8()),
3043 pa.field('b', pa.int16())]))
3044 buffers = a.buffers()
3045 assert len(buffers) == 5
3046 # The parent buffer
3047 null_bitmap = buffers[0].to_pybytes()
3048 assert bytearray(null_bitmap)[0] == 0b00000101
3049 # The child buffers: 'a'
3050 null_bitmap = buffers[1].to_pybytes()
3051 assert bytearray(null_bitmap)[0] == 0b00000011
3052 values = buffers[2].to_pybytes()
3053 assert struct.unpack('bxx', values) == (42,)
3054 # The child buffers: 'b'
3055 null_bitmap = buffers[3].to_pybytes()
3056 assert bytearray(null_bitmap)[0] == 0b00000110
3057 values = buffers[4].to_pybytes()
3058 assert struct.unpack('4xh', values) == (43,)
3059
3060
3061@pytest.mark.numpy

Callers

nothing calls this directly

Calls 5

lenFunction · 0.85
buffersMethod · 0.80
arrayMethod · 0.45
unpackMethod · 0.45
fieldMethod · 0.45

Tested by

no test coverage detected