Skip to content

Commit 290b330

Browse files
apacheGH-49644: [Python] Validate all sequence inputs, not just list/tuple
1 parent fb2b78d commit 290b330

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎python/pyarrow/array.pxi‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,9 @@ def array(object obj, type=None, mask=None, size=None, from_pandas=None,
270270
# the converter only sees the flat storage type, so validate the
271271
# tensor-specific constraints here where the type is still known.
272272
if (isinstance(extension_type, FixedShapeTensorType)
273-
and isinstance(obj, (list, tuple))):
273+
and isinstance(obj, Sequence)
274+
and not _is_array_like(obj)
275+
and not isinstance(obj, (str, bytes, bytearray))):
274276
if extension_type.permutation is not None:
275277
raise NotImplementedError(
276278
"Converting a sequence of arrays to a fixed_shape_tensor with "

‎python/pyarrow/tests/test_extension_type.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,6 +1778,11 @@ def test_tensor_array_from_list_of_ndarrays(np_type_str):
17781778
with pytest.raises(NotImplementedError, match="permutation"):
17791779
pa.array(elements, type=permuted_type)
17801780

1781+
# The validation also applies to non-list sequences (e.g. a deque)
1782+
from collections import deque
1783+
with pytest.raises(NotImplementedError, match="permutation"):
1784+
pa.array(deque(elements), type=permuted_type)
1785+
17811786

17821787
@pytest.mark.numpy
17831788
@pytest.mark.parametrize("tensor_type", (

0 commit comments

Comments
 (0)