diff --git a/py-polars/polars/utils/_construction.py b/py-polars/polars/utils/_construction.py index 30abd67979cb..3097f91a8c2f 100644 --- a/py-polars/polars/utils/_construction.py +++ b/py-polars/polars/utils/_construction.py @@ -1447,7 +1447,10 @@ def numpy_to_pydf( msg = f"`orient` must be one of {{'col', 'row', None}}, got {orient!r}" raise ValueError(msg) else: - msg = f"cannot create DataFrame from array with more than two dimensions; shape = {shape}" + if shape == (): + msg = "cannot create DataFrame from zero-dimensional array" + else: + msg = f"cannot create DataFrame from array with more than two dimensions; shape = {shape}" raise ValueError(msg) if schema is not None and len(schema) != n_columns: diff --git a/py-polars/tests/unit/interop/test_interop.py b/py-polars/tests/unit/interop/test_interop.py index ee886455a67b..440772eaa54f 100644 --- a/py-polars/tests/unit/interop/test_interop.py +++ b/py-polars/tests/unit/interop/test_interop.py @@ -419,6 +419,15 @@ def test_from_numpy() -> None: assert df.shape == (3, 2) assert df.rows() == [(1, 4), (2, 5), (3, 6)] assert df.schema == {"a": pl.UInt32, "b": pl.UInt32} + with pytest.raises( + ValueError, + match="cannot create DataFrame from array with more than two dimensions", + ): + _ = pl.from_numpy(np.array([[[1]]])) + with pytest.raises( + ValueError, match="cannot create DataFrame from zero-dimensional array" + ): + _ = pl.from_numpy(np.array(1)) def test_from_numpy_structured() -> None: