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

Function test_buffers_nested

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

Source from the content-addressed store, hash-verified

2965
2966
2967def test_buffers_nested():
2968 a = pa.array([[1, 2], None, [3, None, 4, 5]], type=pa.list_(pa.int64()))
2969 buffers = a.buffers()
2970 assert len(buffers) == 4
2971 # The parent buffers
2972 null_bitmap = buffers[0].to_pybytes()
2973 assert bytearray(null_bitmap)[0] == 0b00000101
2974 offsets = buffers[1].to_pybytes()
2975 assert struct.unpack('4i', offsets) == (0, 2, 2, 6)
2976 # The child buffers
2977 null_bitmap = buffers[2].to_pybytes()
2978 assert bytearray(null_bitmap)[0] == 0b00110111
2979 values = buffers[3].to_pybytes()
2980 assert struct.unpack('qqq8xqq', values) == (1, 2, 3, 4, 5)
2981
2982 a = pa.array([(42, None), None, (None, 43)],
2983 type=pa.struct([pa.field('a', pa.int8()),
2984 pa.field('b', pa.int16())]))
2985 buffers = a.buffers()
2986 assert len(buffers) == 5
2987 # The parent buffer
2988 null_bitmap = buffers[0].to_pybytes()
2989 assert bytearray(null_bitmap)[0] == 0b00000101
2990 # The child buffers: 'a'
2991 null_bitmap = buffers[1].to_pybytes()
2992 assert bytearray(null_bitmap)[0] == 0b00000011
2993 values = buffers[2].to_pybytes()
2994 assert struct.unpack('bxx', values) == (42,)
2995 # The child buffers: 'b'
2996 null_bitmap = buffers[3].to_pybytes()
2997 assert bytearray(null_bitmap)[0] == 0b00000110
2998 values = buffers[4].to_pybytes()
2999 assert struct.unpack('4xh', values) == (43,)
3000
3001
3002@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