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

Function test_map_from_dicts

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

Source from the content-addressed store, hash-verified

2114
2115
2116def test_map_from_dicts():
2117 data = [[{'key': b'a', 'value': 1}, {'key': b'b', 'value': 2}],
2118 [{'key': b'c', 'value': 3}],
2119 [{'key': b'd', 'value': 4}, {'key': b'e', 'value': 5},
2120 {'key': b'f', 'value': None}],
2121 [{'key': b'g', 'value': 7}]]
2122 expected = [[(d['key'], d['value']) for d in entry] for entry in data]
2123
2124 arr = pa.array(expected, type=pa.map_(pa.binary(), pa.int32()))
2125
2126 assert arr.to_pylist() == expected
2127
2128 # With omitted values
2129 data[1] = None
2130 expected[1] = None
2131
2132 arr = pa.array(expected, type=pa.map_(pa.binary(), pa.int32()))
2133
2134 assert arr.to_pylist() == expected
2135
2136 # Invalid dictionary
2137 for entry in [[{'value': 5}], [{}], [{'k': 1, 'v': 2}]]:
2138 with pytest.raises(ValueError, match="Invalid Map"):
2139 pa.array([entry], type=pa.map_('i4', 'i4'))
2140
2141 # Invalid dictionary types
2142 for entry in [[{'key': '1', 'value': 5}], [{'key': {'value': 2}}]]:
2143 with pytest.raises(pa.ArrowInvalid, match="tried to convert to int"):
2144 pa.array([entry], type=pa.map_('i4', 'i4'))
2145
2146
2147def test_map_from_tuples():

Callers

nothing calls this directly

Calls 1

arrayMethod · 0.45

Tested by

no test coverage detected