Skip to content

Commit 90c2ac4

Browse files
apacheGH-49644: [Python] Make fixed_size_list test deterministic and cover C-order flatten
1 parent 8fa3bcf commit 90c2ac4

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

‎python/pyarrow/tests/test_array.py‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2928,18 +2928,26 @@ def test_array_from_invalid_dim_raises():
29282928
def test_fixed_size_list_from_multidim_ndarray():
29292929
# GH-49644: a fixed-size list can be built from multi-dimensional ndarray
29302930
# elements by flattening them in C order.
2931-
arr = pa.array([np.array([[1, 2, 3]]), np.array([[4, 5, 6]])],
2931+
arr = pa.array([np.array([[1, 2, 3]], dtype=np.int64),
2932+
np.array([[4, 5, 6]], dtype=np.int64)],
29322933
type=pa.list_(pa.int64(), 3))
29332934
assert arr.type == pa.list_(pa.int64(), 3)
29342935
assert arr.to_pylist() == [[1, 2, 3], [4, 5, 6]]
29352936

2937+
# A non-trivial 2D shape confirms values are flattened in C (row-major) order
2938+
arr = pa.array([np.array([[1, 2], [3, 4]], dtype=np.int64)],
2939+
type=pa.list_(pa.int64(), 4))
2940+
assert arr.to_pylist() == [[1, 2, 3, 4]]
2941+
29362942
# The flattened length must still match the fixed size
29372943
with pytest.raises(pa.lib.ArrowInvalid):
2938-
pa.array([np.array([[1, 2], [3, 4]])], type=pa.list_(pa.int64(), 3))
2944+
pa.array([np.array([[1, 2], [3, 4]], dtype=np.int64)],
2945+
type=pa.list_(pa.int64(), 3))
29392946

29402947
# Variable-sized lists still require 1-dimensional values
29412948
with pytest.raises(pa.lib.ArrowInvalid, match="1-dimensional"):
2942-
pa.array([np.array([[1, 2, 3]])], type=pa.list_(pa.int64()))
2949+
pa.array([np.array([[1, 2, 3]], dtype=np.int64)],
2950+
type=pa.list_(pa.int64()))
29432951

29442952

29452953
@pytest.mark.numpy

0 commit comments

Comments
 (0)