| 4356 | @pytest.mark.parametrize("value_type", (pa.string, pa.int16, pa.float64)) |
| 4357 | @pytest.mark.parametrize("list_type", (pa.list_, pa.large_list, "fixed")) |
| 4358 | def test_list_slice_output_variable(start, stop, step, value_type, list_type): |
| 4359 | if list_type == "fixed": |
| 4360 | data = [[1, 2, 3], [4, 5, None], [6, None, None], None] |
| 4361 | arr = pa.array( |
| 4362 | data, |
| 4363 | pa.list_(pa.int8(), 3)).cast(pa.list_(value_type(), 3)) |
| 4364 | else: |
| 4365 | data = [[1, 2, 3], [4, 5], [6], None] |
| 4366 | arr = pa.array(data, |
| 4367 | pa.list_(pa.int8())).cast(list_type(value_type())) |
| 4368 | |
| 4369 | # Gets same list type (ListArray vs LargeList) |
| 4370 | if list_type == "fixed": |
| 4371 | list_type = pa.list_ # non fixed output type |
| 4372 | |
| 4373 | result = pc.list_slice(arr, start, stop, step, |
| 4374 | return_fixed_size_list=False) |
| 4375 | assert result.type == list_type(value_type()) |
| 4376 | |
| 4377 | pylist = result.cast(pa.list_(pa.int8())).to_pylist() |
| 4378 | |
| 4379 | # Variable output slicing follows Python's slice semantics |
| 4380 | expected = [d[start:stop:step] if d is not None else None for d in data] |
| 4381 | assert pylist == expected |
| 4382 | |
| 4383 | |
| 4384 | @pytest.mark.parametrize("return_fixed_size", (True, False, None)) |