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

Function test_buffers_primitive

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

Source from the content-addressed store, hash-verified

2928
2929@pytest.mark.numpy
2930def test_buffers_primitive():
2931 a = pa.array([1, 2, None, 4], type=pa.int16())
2932 buffers = a.buffers()
2933 assert len(buffers) == 2
2934 null_bitmap = buffers[0].to_pybytes()
2935 assert 1 <= len(null_bitmap) <= 64 # XXX this is varying
2936 assert bytearray(null_bitmap)[0] == 0b00001011
2937
2938 # Slicing does not affect the buffers but the offset
2939 a_sliced = a[1:]
2940 buffers = a_sliced.buffers()
2941 a_sliced.offset == 1
2942 assert len(buffers) == 2
2943 null_bitmap = buffers[0].to_pybytes()
2944 assert 1 <= len(null_bitmap) <= 64 # XXX this is varying
2945 assert bytearray(null_bitmap)[0] == 0b00001011
2946
2947 assert struct.unpack('hhxxh', buffers[1].to_pybytes()) == (1, 2, 4)
2948
2949 a = pa.array(np.int8([4, 5, 6]))
2950 buffers = a.buffers()
2951 assert len(buffers) == 2
2952 # No null bitmap from Numpy int array
2953 assert buffers[0] is None
2954 assert struct.unpack('3b', buffers[1].to_pybytes()) == (4, 5, 6)
2955
2956 a = pa.array([b'foo!', None, b'bar!!'])
2957 buffers = a.buffers()
2958 assert len(buffers) == 3
2959 null_bitmap = buffers[0].to_pybytes()
2960 assert bytearray(null_bitmap)[0] == 0b00000101
2961 offsets = buffers[1].to_pybytes()
2962 assert struct.unpack('4i', offsets) == (0, 4, 4, 9)
2963 values = buffers[2].to_pybytes()
2964 assert values == b'foo!bar!!'
2965
2966
2967def 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