File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed
Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -321,6 +321,12 @@ def array(
321321 return data .copy ()
322322 return data
323323
324+ # to avoid returning an array of string representation of objects.
325+ if dtype == StringDtype ():
326+ ndarr = np .array (data )
327+ if ndarr .ndim != 1 :
328+ raise TypeError ("Values must be a 1D list-like" )
329+
324330 if isinstance (dtype , ExtensionDtype ):
325331 cls = dtype .construct_array_type ()
326332 return cls ._from_sequence (data , dtype = dtype , copy = copy )
Original file line number Diff line number Diff line change @@ -460,6 +460,12 @@ def test_nd_raises(data):
460460 pd .array (data , dtype = "int64" )
461461
462462
463+ @pytest .mark .parametrize ("data" , [[["a" ], ["b" ]]])
464+ def test_not_1D_like_raises (data ):
465+ with pytest .raises (TypeError , match = "Values must be a 1D list-like" ):
466+ pd .array (data , dtype = pd .StringDtype ())
467+
468+
463469def test_scalar_raises ():
464470 with pytest .raises (ValueError , match = "Cannot pass scalar '1'" ):
465471 pd .array (1 )
You can’t perform that action at this time.
0 commit comments