Skip to content

Commit e452752

Browse files
check for ndim when dtype is object
1 parent 80e0130 commit e452752

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

pandas/core/arrays/numpy_.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,6 @@ def __init__(
122122
# Technically we support 2, but do not advertise that fact.
123123
raise ValueError("NumpyExtensionArray must be 1-dimensional.")
124124

125-
if (values.dtype == object and values.ndim != 1):
126-
raise ValueError("NumpyExtensionArray must be 1-dimensional.")
127-
128125
if copy:
129126
values = values.copy()
130127

pandas/core/construction.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ def array(
304304
raise ValueError(msg)
305305
elif isinstance(data, ABCDataFrame):
306306
raise TypeError("Cannot pass DataFrame to 'pandas.array'")
307+
elif isinstance(data, np.ndarray) and data.ndim != 1 and dtype == object:
308+
raise ValueError("NumpyExtensionArray must be 1-dimensional.")
307309

308310
if dtype is None and isinstance(data, (ABCSeries, ABCIndex, ExtensionArray)):
309311
# Note: we exclude np.ndarray here, will do type inference on it

0 commit comments

Comments
 (0)