Skip to content

Commit a505d35

Browse files
committed
BUG: Fix array creation for string dtype with inconsistent list lengths (pandas-dev#61155)
1 parent e58f383 commit a505d35

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

pandas/core/arrays/string_.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ def _from_sequence(
639639
dtype = StringDtype(storage="python")
640640

641641
from pandas.core.arrays.masked import BaseMaskedArray
642-
642+
643643
na_value = dtype.na_value
644644
if isinstance(scalars, BaseMaskedArray):
645645
# avoid costly conversion to object dtype
@@ -655,6 +655,8 @@ def _from_sequence(
655655
# zero_copy_only to True which caused problems see GH#52076
656656
scalars = np.array(scalars)
657657
# convert non-na-likes to str, and nan-likes to StringDtype().na_value
658+
if isinstance(scalars, list) and all(isinstance(x,list) for x in scalars):
659+
scalars =[str(x) for x in scalars]
658660
result = lib.ensure_string_array(scalars, na_value=na_value, copy=copy)
659661

660662
# Manually creating new array avoids the validation step in the __init__, so is

0 commit comments

Comments
 (0)