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

Function test_struct_fields_options

python/pyarrow/tests/test_compute.py:3852–3886  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3850
3851
3852def test_struct_fields_options():
3853 a = pa.array([4, 5, 6], type=pa.int64())
3854 b = pa.array(["bar", None, ""])
3855 c = pa.StructArray.from_arrays([a, b], ["a", "b"])
3856 arr = pa.StructArray.from_arrays([a, c], ["a", "c"])
3857
3858 assert pc.struct_field(arr, '.c.b') == b
3859 assert pc.struct_field(arr, b'.c.b') == b
3860 assert pc.struct_field(arr, ['c', 'b']) == b
3861 assert pc.struct_field(arr, [1, 'b']) == b
3862 assert pc.struct_field(arr, (b'c', 'b')) == b
3863 assert pc.struct_field(arr, pc.field(('c', 'b'))) == b
3864
3865 assert pc.struct_field(arr, '.a') == a
3866 assert pc.struct_field(arr, ['a']) == a
3867 assert pc.struct_field(arr, 'a') == a
3868 assert pc.struct_field(arr, pc.field(('a',))) == a
3869
3870 assert pc.struct_field(arr, indices=[1, 1]) == b
3871 assert pc.struct_field(arr, (1, 1)) == b
3872 assert pc.struct_field(arr, [0]) == a
3873 assert pc.struct_field(arr, []) == arr
3874
3875 with pytest.raises(pa.ArrowInvalid, match="No match for FieldRef"):
3876 pc.struct_field(arr, 'foo')
3877
3878 with pytest.raises(pa.ArrowInvalid, match="No match for FieldRef"):
3879 pc.struct_field(arr, '.c.foo')
3880
3881 # drill into a non-struct array and continue to ask for a field
3882 with pytest.raises(pa.ArrowInvalid, match="No match for FieldRef"):
3883 pc.struct_field(arr, '.a.foo')
3884
3885 with pytest.raises(pa.ArrowInvalid, match="cannot be called without options"):
3886 pc.struct_field(arr)
3887
3888
3889def test_case_when():

Callers

nothing calls this directly

Calls 2

arrayMethod · 0.45
fieldMethod · 0.45

Tested by

no test coverage detected