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

Function test_struct_array_flatten

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

Source from the content-addressed store, hash-verified

3502
3503
3504def test_struct_array_flatten():
3505 ty = pa.struct([pa.field('x', pa.int16()),
3506 pa.field('y', pa.float32())])
3507 a = pa.array([(1, 2.5), (3, 4.5), (5, 6.5)], type=ty)
3508 xs, ys = a.flatten()
3509 assert xs.type == pa.int16()
3510 assert ys.type == pa.float32()
3511 assert xs.to_pylist() == [1, 3, 5]
3512 assert ys.to_pylist() == [2.5, 4.5, 6.5]
3513 xs, ys = a[1:].flatten()
3514 assert xs.to_pylist() == [3, 5]
3515 assert ys.to_pylist() == [4.5, 6.5]
3516
3517 a = pa.array([(1, 2.5), None, (3, 4.5)], type=ty)
3518 xs, ys = a.flatten()
3519 assert xs.to_pylist() == [1, None, 3]
3520 assert ys.to_pylist() == [2.5, None, 4.5]
3521 xs, ys = a[1:].flatten()
3522 assert xs.to_pylist() == [None, 3]
3523 assert ys.to_pylist() == [None, 4.5]
3524
3525 a = pa.array([(1, None), (2, 3.5), (None, 4.5)], type=ty)
3526 xs, ys = a.flatten()
3527 assert xs.to_pylist() == [1, 2, None]
3528 assert ys.to_pylist() == [None, 3.5, 4.5]
3529 xs, ys = a[1:].flatten()
3530 assert xs.to_pylist() == [2, None]
3531 assert ys.to_pylist() == [3.5, 4.5]
3532
3533 a = pa.array([(1, None), None, (None, 2.5)], type=ty)
3534 xs, ys = a.flatten()
3535 assert xs.to_pylist() == [1, None, None]
3536 assert ys.to_pylist() == [None, None, 2.5]
3537 xs, ys = a[1:].flatten()
3538 assert xs.to_pylist() == [None, None]
3539 assert ys.to_pylist() == [None, 2.5]
3540
3541
3542def test_struct_array_field():

Callers

nothing calls this directly

Calls 2

fieldMethod · 0.45
arrayMethod · 0.45

Tested by

no test coverage detected