diff --git a/py-polars/polars/datatypes/classes.py b/py-polars/polars/datatypes/classes.py index eff08a5eb0c4..f33e00d2a494 100644 --- a/py-polars/polars/datatypes/classes.py +++ b/py-polars/polars/datatypes/classes.py @@ -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:]) diff --git a/py-polars/tests/unit/datatypes/test_array.py b/py-polars/tests/unit/datatypes/test_array.py index cfff9514a97e..b55a5d253287 100644 --- a/py-polars/tests/unit/datatypes/test_array.py +++ b/py-polars/tests/unit/datatypes/test_array.py @@ -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))