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

Function test_buffers_primitive

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

Source from the content-addressed store, hash-verified

3045
3046@pytest.mark.numpy
3047def test_buffers_primitive():
3048 a = pa.array([1, 2, None, 4], type=pa.int16())
3049 buffers = a.buffers()
3050 assert len(buffers) == 2
3051 null_bitmap = buffers[0].to_pybytes()
3052 assert 1 <= len(null_bitmap) <= 64 # XXX this is varying
3053 assert bytearray(null_bitmap)[0] == 0b00001011
3054
3055 # Slicing does not affect the buffers but the offset
3056 a_sliced = a[1:]
3057 buffers = a_sliced.buffers()
3058 a_sliced.offset == 1
3059 assert len(buffers) == 2
3060 null_bitmap = buffers[0].to_pybytes()
3061 assert 1 <= len(null_bitmap) <= 64 # XXX this is varying
3062 assert bytearray(null_bitmap)[0] == 0b00001011
3063
3064 assert struct.unpack('hhxxh', buffers[1].to_pybytes()) == (1, 2, 4)
3065
3066 a = pa.array(np.int8([4, 5, 6]))
3067 buffers = a.buffers()
3068 assert len(buffers) == 2
3069 # No null bitmap from Numpy int array
3070 assert buffers[0] is None
3071 assert struct.unpack('3b', buffers[1].to_pybytes()) == (4, 5, 6)
3072
3073 a = pa.array([b'foo!', None, b'bar!!'])
3074 buffers = a.buffers()
3075 assert len(buffers) == 3
3076 null_bitmap = buffers[0].to_pybytes()
3077 assert bytearray(null_bitmap)[0] == 0b00000101
3078 offsets = buffers[1].to_pybytes()
3079 assert struct.unpack('4i', offsets) == (0, 4, 4, 9)
3080 values = buffers[2].to_pybytes()
3081 assert values == b'foo!bar!!'
3082
3083
3084def 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