Skip to content

Commit 2eb0109

Browse files
authored
fix(python): Validate pl.Array shape argument types (#20915)
1 parent c7243bc commit 2eb0109

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Diff for: py-polars/polars/datatypes/classes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ def __init__(
813813
self.size = shape
814814
self.shape = (shape,) + inner_shape
815815

816-
elif isinstance(shape, tuple):
816+
elif isinstance(shape, tuple) and isinstance(shape[0], int): # type: ignore[redundant-expr]
817817
if len(shape) > 1:
818818
inner_parsed = Array(inner_parsed, shape[1:])
819819

Diff for: py-polars/tests/unit/datatypes/test_array.py

+5
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,11 @@ def test_array_missing_shape() -> None:
329329
pl.Array(pl.Int8)
330330

331331

332+
def test_array_invalid_shape_type() -> None:
333+
with pytest.raises(TypeError, match="invalid input for shape"):
334+
pl.Array(pl.Int8, shape=("x",)) # type: ignore[arg-type]
335+
336+
332337
def test_array_invalid_physical_type_18920() -> None:
333338
s1 = pl.Series("x", [[1000, 2000]], pl.List(pl.Datetime))
334339
s2 = pl.Series("x", [None], pl.List(pl.Datetime))

0 commit comments

Comments
 (0)