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

Function test_buffers_primitive

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

Source from the content-addressed store, hash-verified

2987
2988@pytest.mark.numpy
2989def test_buffers_primitive():
2990 a = pa.array([1, 2, None, 4], type=pa.int16())
2991 buffers = a.buffers()
2992 assert len(buffers) == 2
2993 null_bitmap = buffers[0].to_pybytes()
2994 assert 1 <= len(null_bitmap) <= 64 # XXX this is varying
2995 assert bytearray(null_bitmap)[0] == 0b00001011
2996
2997 # Slicing does not affect the buffers but the offset
2998 a_sliced = a[1:]
2999 buffers = a_sliced.buffers()
3000 a_sliced.offset == 1
3001 assert len(buffers) == 2
3002 null_bitmap = buffers[0].to_pybytes()
3003 assert 1 <= len(null_bitmap) <= 64 # XXX this is varying
3004 assert bytearray(null_bitmap)[0] == 0b00001011
3005
3006 assert struct.unpack('hhxxh', buffers[1].to_pybytes()) == (1, 2, 4)
3007
3008 a = pa.array(np.int8([4, 5, 6]))
3009 buffers = a.buffers()
3010 assert len(buffers) == 2
3011 # No null bitmap from Numpy int array
3012 assert buffers[0] is None
3013 assert struct.unpack('3b', buffers[1].to_pybytes()) == (4, 5, 6)
3014
3015 a = pa.array([b'foo!', None, b'bar!!'])
3016 buffers = a.buffers()
3017 assert len(buffers) == 3
3018 null_bitmap = buffers[0].to_pybytes()
3019 assert bytearray(null_bitmap)[0] == 0b00000101
3020 offsets = buffers[1].to_pybytes()
3021 assert struct.unpack('4i', offsets) == (0, 4, 4, 9)
3022 values = buffers[2].to_pybytes()
3023 assert values == b'foo!bar!!'
3024
3025
3026def test_buffers_nested():

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected