Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pandas/core/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ def array(
# StringArray/ArrowStringArray depending on pd.options.mode.string_storage
dtype = StringDtype()
cls = dtype.construct_array_type()
if data.ndim != 1:
raise ValueError("NumpyExtensionArray must be 1-dimensional")
Comment on lines +363 to +364
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test shows that the verification shouldn't be put here. I think the correct place is pandas/core/arrays/numpy_.py

return cls._from_sequence(data, dtype=dtype, copy=copy)

elif data.dtype.kind in "iu":
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/arrays/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,10 @@ 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)])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can fix the formatting with pre-commit. The docs have a section about it. It's also good to create a development environment.

To fix the formatting, setup pre-commit and run

pre-commit run --files pandas/tests/arrays/test_array.py

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