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

Function test_struct_array_field

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

Source from the content-addressed store, hash-verified

3540
3541
3542def test_struct_array_field():
3543 ty = pa.struct([pa.field('x', pa.int16()),
3544 pa.field('y', pa.float32())])
3545 a = pa.array([(1, 2.5), (3, 4.5), (5, 6.5)], type=ty)
3546
3547 x0 = a.field(0)
3548 y0 = a.field(1)
3549 x1 = a.field(-2)
3550 y1 = a.field(-1)
3551 x2 = a.field('x')
3552 y2 = a.field('y')
3553
3554 assert isinstance(x0, pa.lib.Int16Array)
3555 assert isinstance(y1, pa.lib.FloatArray)
3556 assert x0.equals(pa.array([1, 3, 5], type=pa.int16()))
3557 assert y0.equals(pa.array([2.5, 4.5, 6.5], type=pa.float32()))
3558 assert x0.equals(x1)
3559 assert x0.equals(x2)
3560 assert y0.equals(y1)
3561 assert y0.equals(y2)
3562
3563 for invalid_index in [None, pa.int16()]:
3564 with pytest.raises(TypeError):
3565 a.field(invalid_index)
3566
3567 for invalid_index in [3, -3]:
3568 with pytest.raises(IndexError):
3569 a.field(invalid_index)
3570
3571 for invalid_name in ['z', '']:
3572 with pytest.raises(KeyError):
3573 a.field(invalid_name)
3574
3575
3576def test_struct_array_flattened_field():

Callers

nothing calls this directly

Calls 3

equalsMethod · 0.80
fieldMethod · 0.45
arrayMethod · 0.45

Tested by

no test coverage detected