()
| 1648 | |
| 1649 | |
| 1650 | def test_sparse_union_array_slice_with_nulls(): |
| 1651 | # GH-50105: Sliced sparse union element access can return incorrect values. |
| 1652 | type_ids = pa.array([0, 1, 0, 1, 0], type=pa.int8()) |
| 1653 | arr = pa.UnionArray.from_sparse( |
| 1654 | type_ids, |
| 1655 | [ |
| 1656 | pa.array([None, 20, 30, 40, 50]), |
| 1657 | pa.array(["a", "b", "c", None, "e"]), |
| 1658 | ], |
| 1659 | ) |
| 1660 | |
| 1661 | # arr == [None, "b", 30, None, 50]. |
| 1662 | def check_values(array, expected): |
| 1663 | assert [array[i].as_py() for i in range(len(array))] == expected |
| 1664 | assert array.to_pylist() == expected |
| 1665 | |
| 1666 | check_values(arr, [None, "b", 30, None, 50]) |
| 1667 | |
| 1668 | # arr.slice(1, 4) == ["b", 30, None, 50]. |
| 1669 | check_values(arr.slice(1, 4), ["b", 30, None, 50]) |
| 1670 | |
| 1671 | ints_with_offset = pa.array([999, None, 20, 30, 40, 50], |
| 1672 | type=pa.int64())[1:] |
| 1673 | strs_with_offset = pa.array(["z", "a", "b", "c", None, "e"])[1:] |
| 1674 | arr_with_sliced_children = pa.UnionArray.from_sparse( |
| 1675 | type_ids, [ints_with_offset, strs_with_offset] |
| 1676 | ) |
| 1677 | |
| 1678 | # arr_with_sliced_children == [None, "b", 30, None, 50]. |
| 1679 | check_values(arr_with_sliced_children, [None, "b", 30, None, 50]) |
| 1680 | |
| 1681 | # arr_with_sliced_children.slice(1, 4) == ["b", 30, None, 50]. |
| 1682 | check_values(arr_with_sliced_children.slice(1, 4), ["b", 30, None, 50]) |
| 1683 | |
| 1684 | |
| 1685 | def test_union_array_slice(): |
nothing calls this directly
no test coverage detected