Skip to content

Commit

Permalink
fix(python): Validate pl.Array shape argument types (pola-rs#20915)
Browse files Browse the repository at this point in the history
  • Loading branch information
FBruzzesi authored Jan 25, 2025
1 parent c7243bc commit 2eb0109
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion py-polars/polars/datatypes/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ def __init__(
self.size = shape
self.shape = (shape,) + inner_shape

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

Expand Down
5 changes: 5 additions & 0 deletions py-polars/tests/unit/datatypes/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@ def test_array_missing_shape() -> None:
pl.Array(pl.Int8)


def test_array_invalid_shape_type() -> None:
with pytest.raises(TypeError, match="invalid input for shape"):
pl.Array(pl.Int8, shape=("x",)) # type: ignore[arg-type]


def test_array_invalid_physical_type_18920() -> None:
s1 = pl.Series("x", [[1000, 2000]], pl.List(pl.Datetime))
s2 = pl.Series("x", [None], pl.List(pl.Datetime))
Expand Down

0 comments on commit 2eb0109

Please sign in to comment.