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

Function test_chunked_array_getitem

python/pyarrow/tests/test_table.py:181–205  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

179
180@pytest.mark.numpy
181def test_chunked_array_getitem():
182 data = [
183 pa.array([1, 2, 3]),
184 pa.array([4, 5, 6])
185 ]
186 data = pa.chunked_array(data)
187 assert data[1].as_py() == 2
188 assert data[-1].as_py() == 6
189 assert data[-6].as_py() == 1
190 with pytest.raises(IndexError):
191 data[6]
192 with pytest.raises(IndexError):
193 data[-7]
194 # Ensure this works with numpy scalars
195 assert data[np.int32(1)].as_py() == 2
196
197 data_slice = data[2:4]
198 assert data_slice.to_pylist() == [3, 4]
199
200 data_slice = data[4:-1]
201 assert data_slice.to_pylist() == [5]
202
203 data_slice = data[99:99]
204 assert data_slice.type == data.type
205 assert data_slice.to_pylist() == []
206
207
208def test_chunked_array_slice():

Callers

nothing calls this directly

Calls 3

chunked_arrayMethod · 0.80
as_pyMethod · 0.80
arrayMethod · 0.45

Tested by

no test coverage detected