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

Function test_structarray

python/pyarrow/tests/test_convert_builtin.py:1803–1827  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1801
1802
1803def test_structarray():
1804 arr = pa.StructArray.from_arrays([], names=[])
1805 assert arr.type == pa.struct([])
1806 assert len(arr) == 0
1807 assert arr.to_pylist() == []
1808
1809 ints = pa.array([None, 2, 3], type=pa.int64())
1810 strs = pa.array(['a', None, 'c'], type=pa.string())
1811 bools = pa.array([True, False, None], type=pa.bool_())
1812 arr = pa.StructArray.from_arrays(
1813 [ints, strs, bools],
1814 ['ints', 'strs', 'bools'])
1815
1816 expected = [
1817 {'ints': None, 'strs': 'a', 'bools': True},
1818 {'ints': 2, 'strs': None, 'bools': False},
1819 {'ints': 3, 'strs': 'c', 'bools': None},
1820 ]
1821
1822 pylist = arr.to_pylist()
1823 assert pylist == expected, (pylist, expected)
1824
1825 # len(names) != len(arrays)
1826 with pytest.raises(ValueError):
1827 pa.StructArray.from_arrays([ints], ['ints', 'strs'])
1828
1829
1830def test_struct_from_dicts():

Callers

nothing calls this directly

Calls 3

lenFunction · 0.85
arrayMethod · 0.45
stringMethod · 0.45

Tested by

no test coverage detected