| 1828 | |
| 1829 | |
| 1830 | def 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 | |
| 1855 | def test_struct_from_dicts_bytes_keys(): |