Skip to content
2 changes: 2 additions & 0 deletions pandas/core/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ def array(
raise ValueError(msg)
elif isinstance(data, ABCDataFrame):
raise TypeError("Cannot pass DataFrame to 'pandas.array'")
elif isinstance(data, np.ndarray) and data.ndim != 1 and dtype == object:
raise ValueError("NumpyExtensionArray must be 1-dimensional.")

if dtype is None and isinstance(data, (ABCSeries, ABCIndex, ExtensionArray)):
# Note: we exclude np.ndarray here, will do type inference on it
Expand Down
12 changes: 9 additions & 3 deletions pandas/tests/arrays/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,16 @@ def test_array_inference_fails(data):
tm.assert_extension_array_equal(result, expected)


@pytest.mark.parametrize("data", [np.array(0)])
def test_nd_raises(data):
@pytest.mark.parametrize(
"data,dtype",
[
(np.array(0), "int64"),
(np.array([[1, 2], ["a", "b"]]), object),
],
)
def test_nd_raises(data, dtype):
with pytest.raises(ValueError, match="NumpyExtensionArray must be 1-dimensional"):
pd.array(data, dtype="int64")
pd.array(data, dtype=dtype)


def test_scalar_raises():
Expand Down
Loading