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

Function test_buffers_nested

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

Source from the content-addressed store, hash-verified

3216
3217
3218def test_buffers_nested():
3219 a = pa.array([[1, 2], None, [3, None, 4, 5]], type=pa.list_(pa.int64()))
3220 buffers = a.buffers()
3221 assert len(buffers) == 4
3222 # The parent buffers
3223 null_bitmap = buffers[0].to_pybytes()
3224 assert bytearray(null_bitmap)[0] == 0b00000101
3225 offsets = buffers[1].to_pybytes()
3226 assert struct.unpack('4i', offsets) == (0, 2, 2, 6)
3227 # The child buffers
3228 null_bitmap = buffers[2].to_pybytes()
3229 assert bytearray(null_bitmap)[0] == 0b00110111
3230 values = buffers[3].to_pybytes()
3231 assert struct.unpack('qqq8xqq', values) == (1, 2, 3, 4, 5)
3232
3233 a = pa.array([(42, None), None, (None, 43)],
3234 type=pa.struct([pa.field('a', pa.int8()),
3235 pa.field('b', pa.int16())]))
3236 buffers = a.buffers()
3237 assert len(buffers) == 5
3238 # The parent buffer
3239 null_bitmap = buffers[0].to_pybytes()
3240 assert bytearray(null_bitmap)[0] == 0b00000101
3241 # The child buffers: 'a'
3242 null_bitmap = buffers[1].to_pybytes()
3243 assert bytearray(null_bitmap)[0] == 0b00000011
3244 values = buffers[2].to_pybytes()
3245 assert struct.unpack('bxx', values) == (42,)
3246 # The child buffers: 'b'
3247 null_bitmap = buffers[3].to_pybytes()
3248 assert bytearray(null_bitmap)[0] == 0b00000110
3249 values = buffers[4].to_pybytes()
3250 assert struct.unpack('4xh', values) == (43,)
3251
3252
3253@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