Skip to content

Commit 8faf120

Browse files
committed
Validate nested iterable depth
1 parent e308e21 commit 8faf120

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

python/pylibcudf/pylibcudf/column.pyx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,12 @@ def _infer_shape(obj: list, depth: int) -> tuple[int, ...]:
217217

218218
shape = (len(obj),)
219219
if depth == 1:
220+
if any(isinstance(value, list) for value in obj):
221+
raise ValueError("Inconsistent inner list shapes")
220222
return shape
221223

224+
if not isinstance(obj[0], list):
225+
raise ValueError("Inconsistent inner list shapes")
222226
first_shape = _infer_shape(obj[0], depth - 1)
223227
for sub in obj[1:]:
224228
if not isinstance(sub, list) or _infer_shape(sub, depth - 1) != first_shape:

python/pylibcudf/tests/test_column_from_iterable.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ def test_from_list_irregular_shapes_raises():
102102
[
103103
[[[1], [2]], [[3, 4], [5, 6]]],
104104
[[[1, 2], [3, 4]], [[5], [6, 7, 8]]],
105+
[[[1]], [2]],
106+
[[[1]], [[[2, 3]]]],
105107
],
106108
)
107109
def test_from_list_deeply_irregular_shapes_raises(data):

0 commit comments

Comments
 (0)