Skip to content

Commit f41daf6

Browse files
Add conditional to check StringDtype
1 parent e452752 commit f41daf6

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

pandas/core/construction.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,10 @@ 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.")
307+
elif isinstance(data, (list, tuple)) and dtype == StringDtype():
308+
for i in data:
309+
if isinstance(i, (np.ndarray, list, tuple)):
310+
raise ValueError("NumpyExtensionArray must be 1-dimensional.")
309311

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

pandas/tests/arrays/test_array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ def test_array_inference_fails(data):
455455
"data,dtype",
456456
[
457457
(np.array(0), "int64"),
458-
(np.array([[1, 2], ["a", "b"]]), object),
458+
([["a"], ["b"]], pd.StringDtype()),
459459
],
460460
)
461461
def test_nd_raises(data, dtype):

0 commit comments

Comments
 (0)