| 1801 | |
| 1802 | |
| 1803 | def 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 | |
| 1830 | def test_struct_from_dicts(): |