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

Function test_struct_array_flattened_field

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

Source from the content-addressed store, hash-verified

3574
3575
3576def test_struct_array_flattened_field():
3577 ty = pa.struct([pa.field('x', pa.int16()),
3578 pa.field('y', pa.float32())])
3579 a = pa.array([(1, 2.5), (3, 4.5), (5, 6.5)], type=ty,
3580 mask=pa.array([False, True, False]))
3581
3582 x0 = a._flattened_field(0)
3583 y0 = a._flattened_field(1)
3584 x1 = a._flattened_field(-2)
3585 y1 = a._flattened_field(-1)
3586 x2 = a._flattened_field('x')
3587 y2 = a._flattened_field('y')
3588
3589 assert isinstance(x0, pa.lib.Int16Array)
3590 assert isinstance(y1, pa.lib.FloatArray)
3591 assert x0.equals(pa.array([1, None, 5], type=pa.int16()))
3592 assert y0.equals(pa.array([2.5, None, 6.5], type=pa.float32()))
3593 assert x0.equals(x1)
3594 assert x0.equals(x2)
3595 assert y0.equals(y1)
3596 assert y0.equals(y2)
3597
3598 for invalid_index in [None, pa.int16()]:
3599 with pytest.raises(TypeError):
3600 a._flattened_field(invalid_index)
3601
3602 for invalid_index in [3, -3]:
3603 with pytest.raises(IndexError):
3604 a._flattened_field(invalid_index)
3605
3606 for invalid_name in ['z', '']:
3607 with pytest.raises(KeyError):
3608 a._flattened_field(invalid_name)
3609
3610
3611def test_empty_cast():

Callers

nothing calls this directly

Calls 3

equalsMethod · 0.80
fieldMethod · 0.45
arrayMethod · 0.45

Tested by

no test coverage detected