Skip to content

Commit ce4c01a

Browse files
add conditional for checking ndim
1 parent b965ef5 commit ce4c01a

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

pandas/core/arrays/numpy_.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ def __init__(
118118
f"'values' must be a NumPy array, not {type(values).__name__}"
119119
)
120120

121-
if values.ndim == 0:
122-
# Technically we support 2, but do not advertise that fact.
121+
if values.ndim != 1:
123122
raise ValueError("NumpyExtensionArray must be 1-dimensional.")
124123

125124
if copy:

pandas/core/construction.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,6 @@ def array(
360360
# StringArray/ArrowStringArray depending on pd.options.mode.string_storage
361361
dtype = StringDtype()
362362
cls = dtype.construct_array_type()
363-
if data.ndim != 1:
364-
raise ValueError("NumpyExtensionArray must be 1-dimensional")
365363
return cls._from_sequence(data, dtype=dtype, copy=copy)
366364

367365
elif data.dtype.kind in "iu":

pandas/tests/arrays/test_array.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,13 @@ def test_array_inference_fails(data):
451451
tm.assert_extension_array_equal(result, expected)
452452

453453

454-
@pytest.mark.parametrize("data,dtype", [(np.array(0),"int64"),(np.array([[1, 2], ["a", "b"]]),object)])
454+
@pytest.mark.parametrize(
455+
"data,dtype",
456+
[
457+
(np.array(0), "int64"),
458+
(np.array([[1, 2], ["a", "b"]]), object),
459+
],
460+
)
455461
def test_nd_raises(data, dtype):
456462
with pytest.raises(ValueError, match="NumpyExtensionArray must be 1-dimensional"):
457463
pd.array(data, dtype=dtype)

0 commit comments

Comments
 (0)