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

Function test_buffers_primitive

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

Source from the content-addressed store, hash-verified

3179
3180@pytest.mark.numpy
3181def test_buffers_primitive():
3182 a = pa.array([1, 2, None, 4], type=pa.int16())
3183 buffers = a.buffers()
3184 assert len(buffers) == 2
3185 null_bitmap = buffers[0].to_pybytes()
3186 assert 1 <= len(null_bitmap) <= 64 # XXX this is varying
3187 assert bytearray(null_bitmap)[0] == 0b00001011
3188
3189 # Slicing does not affect the buffers but the offset
3190 a_sliced = a[1:]
3191 buffers = a_sliced.buffers()
3192 a_sliced.offset == 1
3193 assert len(buffers) == 2
3194 null_bitmap = buffers[0].to_pybytes()
3195 assert 1 <= len(null_bitmap) <= 64 # XXX this is varying
3196 assert bytearray(null_bitmap)[0] == 0b00001011
3197
3198 assert struct.unpack('hhxxh', buffers[1].to_pybytes()) == (1, 2, 4)
3199
3200 a = pa.array(np.int8([4, 5, 6]))
3201 buffers = a.buffers()
3202 assert len(buffers) == 2
3203 # No null bitmap from Numpy int array
3204 assert buffers[0] is None
3205 assert struct.unpack('3b', buffers[1].to_pybytes()) == (4, 5, 6)
3206
3207 a = pa.array([b'foo!', None, b'bar!!'])
3208 buffers = a.buffers()
3209 assert len(buffers) == 3
3210 null_bitmap = buffers[0].to_pybytes()
3211 assert bytearray(null_bitmap)[0] == 0b00000101
3212 offsets = buffers[1].to_pybytes()
3213 assert struct.unpack('4i', offsets) == (0, 4, 4, 9)
3214 values = buffers[2].to_pybytes()
3215 assert values == b'foo!bar!!'
3216
3217
3218def 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