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

Function test_buffers_nested

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

Source from the content-addressed store, hash-verified

3082
3083
3084def test_buffers_nested():
3085 a = pa.array([[1, 2], None, [3, None, 4, 5]], type=pa.list_(pa.int64()))
3086 buffers = a.buffers()
3087 assert len(buffers) == 4
3088 # The parent buffers
3089 null_bitmap = buffers[0].to_pybytes()
3090 assert bytearray(null_bitmap)[0] == 0b00000101
3091 offsets = buffers[1].to_pybytes()
3092 assert struct.unpack('4i', offsets) == (0, 2, 2, 6)
3093 # The child buffers
3094 null_bitmap = buffers[2].to_pybytes()
3095 assert bytearray(null_bitmap)[0] == 0b00110111
3096 values = buffers[3].to_pybytes()
3097 assert struct.unpack('qqq8xqq', values) == (1, 2, 3, 4, 5)
3098
3099 a = pa.array([(42, None), None, (None, 43)],
3100 type=pa.struct([pa.field('a', pa.int8()),
3101 pa.field('b', pa.int16())]))
3102 buffers = a.buffers()
3103 assert len(buffers) == 5
3104 # The parent buffer
3105 null_bitmap = buffers[0].to_pybytes()
3106 assert bytearray(null_bitmap)[0] == 0b00000101
3107 # The child buffers: 'a'
3108 null_bitmap = buffers[1].to_pybytes()
3109 assert bytearray(null_bitmap)[0] == 0b00000011
3110 values = buffers[2].to_pybytes()
3111 assert struct.unpack('bxx', values) == (42,)
3112 # The child buffers: 'b'
3113 null_bitmap = buffers[3].to_pybytes()
3114 assert bytearray(null_bitmap)[0] == 0b00000110
3115 values = buffers[4].to_pybytes()
3116 assert struct.unpack('4xh', values) == (43,)
3117
3118
3119@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