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

Function test_union

python/pyarrow/tests/test_scalars.py:888–934  ·  view source on GitHub ↗
(pickle_module)

Source from the content-addressed store, hash-verified

886
887
888def test_union(pickle_module):
889 # sparse
890 arr = pa.UnionArray.from_sparse(
891 pa.array([0, 0, 1, 1], type=pa.int8()),
892 [
893 pa.array(["a", "b", "c", "d"]),
894 pa.array([1, 2, 3, 4])
895 ]
896 )
897 for s in arr:
898 s.validate(full=True)
899 assert isinstance(s, pa.UnionScalar)
900 assert s.type.equals(arr.type)
901 assert s.is_valid is True
902 with pytest.raises(pa.ArrowNotImplementedError):
903 pickle_module.loads(pickle_module.dumps(s))
904
905 assert arr[0].type_code == 0
906 assert arr[0].as_py() == "a"
907 assert arr[1].type_code == 0
908 assert arr[1].as_py() == "b"
909 assert arr[2].type_code == 1
910 assert arr[2].as_py() == 3
911 assert arr[3].type_code == 1
912 assert arr[3].as_py() == 4
913
914 # dense
915 arr = pa.UnionArray.from_dense(
916 types=pa.array([0, 1, 0, 0, 1, 1, 0], type='int8'),
917 value_offsets=pa.array([0, 0, 2, 1, 1, 2, 3], type='int32'),
918 children=[
919 pa.array([b'a', b'b', b'c', b'd'], type='binary'),
920 pa.array([1, 2, 3], type='int64')
921 ]
922 )
923 for s in arr:
924 s.validate(full=True)
925 assert isinstance(s, pa.UnionScalar)
926 assert s.type.equals(arr.type)
927 assert s.is_valid is True
928 with pytest.raises(pa.ArrowNotImplementedError):
929 pickle_module.loads(pickle_module.dumps(s))
930
931 assert arr[0].type_code == 0
932 assert arr[0].as_py() == b'a'
933 assert arr[5].type_code == 1
934 assert arr[5].as_py() == 3
935
936
937def test_map_scalar_as_py_with_custom_field_name():

Callers

nothing calls this directly

Calls 6

equalsMethod · 0.80
loadsMethod · 0.80
dumpsMethod · 0.80
as_pyMethod · 0.80
arrayMethod · 0.45
validateMethod · 0.45

Tested by

no test coverage detected