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

Function test_list_view_from_arrays

python/pyarrow/tests/test_array.py:4346–4412  ·  view source on GitHub ↗
(list_array_type, list_type_factory)

Source from the content-addressed store, hash-verified

4344 [(pa.ListViewArray, pa.list_view),
4345 (pa.LargeListViewArray, pa.large_list_view)])
4346def test_list_view_from_arrays(list_array_type, list_type_factory):
4347 # test in order offsets, similar to ListArray representation
4348 values = [1, 2, 3, 4, 5, 6, None, 7]
4349 offsets = [0, 2, 4, 6]
4350 sizes = [2, 2, 2, 2]
4351 array = list_array_type.from_arrays(offsets, sizes, values)
4352
4353 assert array.to_pylist() == [[1, 2], [3, 4], [5, 6], [None, 7]]
4354 assert array.values.to_pylist() == values
4355 assert array.offsets.to_pylist() == offsets
4356 assert array.sizes.to_pylist() == sizes
4357
4358 # with specified type
4359 typ = list_type_factory(pa.field("name", pa.int64()))
4360 result = list_array_type.from_arrays(offsets, sizes, values, typ)
4361 assert result.type == typ
4362 assert result.type.value_field.name == "name"
4363
4364 # with mismatching type
4365 typ = list_type_factory(pa.binary())
4366 with pytest.raises(TypeError):
4367 list_array_type.from_arrays(offsets, sizes, values, type=typ)
4368
4369 # test out of order offsets with overlapping values
4370 values = [1, 2, 3, 4]
4371 offsets = [2, 1, 0]
4372 sizes = [2, 2, 2]
4373 array = list_array_type.from_arrays(offsets, sizes, values)
4374
4375 assert array.to_pylist() == [[3, 4], [2, 3], [1, 2]]
4376 assert array.values.to_pylist() == values
4377 assert array.offsets.to_pylist() == offsets
4378 assert array.sizes.to_pylist() == sizes
4379
4380 # test null offsets and empty list values
4381 values = []
4382 offsets = [0, None]
4383 sizes = [0, 0]
4384 array = list_array_type.from_arrays(offsets, sizes, values)
4385
4386 assert array.to_pylist() == [[], None]
4387 assert array.values.to_pylist() == values
4388 assert array.offsets.to_pylist() == [0, 0]
4389 assert array.sizes.to_pylist() == sizes
4390
4391 # test null sizes and empty list values
4392 values = []
4393 offsets = [0, 0]
4394 sizes = [None, 0]
4395 array = list_array_type.from_arrays(offsets, sizes, values)
4396
4397 assert array.to_pylist() == [None, []]
4398 assert array.values.to_pylist() == values
4399 assert array.offsets.to_pylist() == offsets
4400 assert array.sizes.to_pylist() == [0, 0]
4401
4402 # test null bitmask
4403 values = [1, 2]

Callers

nothing calls this directly

Calls 2

fieldMethod · 0.45
arrayMethod · 0.45

Tested by

no test coverage detected