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

Function test_struct_from_dicts

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

Source from the content-addressed store, hash-verified

1828
1829
1830def test_struct_from_dicts():
1831 ty = pa.struct([pa.field('a', pa.int32()),
1832 pa.field('b', pa.string()),
1833 pa.field('c', pa.bool_())])
1834 arr = pa.array([], type=ty)
1835 assert arr.to_pylist() == []
1836
1837 data = [{'a': 5, 'b': 'foo', 'c': True},
1838 {'a': 6, 'b': 'bar', 'c': False}]
1839 arr = pa.array(data, type=ty)
1840 assert arr.to_pylist() == data
1841
1842 # With omitted values
1843 data = [{'a': 5, 'c': True},
1844 None,
1845 {},
1846 {'a': None, 'b': 'bar'}]
1847 arr = pa.array(data, type=ty)
1848 expected = [{'a': 5, 'b': None, 'c': True},
1849 None,
1850 {'a': None, 'b': None, 'c': None},
1851 {'a': None, 'b': 'bar', 'c': None}]
1852 assert arr.to_pylist() == expected
1853
1854
1855def test_struct_from_dicts_bytes_keys():

Callers

nothing calls this directly

Calls 3

fieldMethod · 0.45
stringMethod · 0.45
arrayMethod · 0.45

Tested by

no test coverage detected