Skip to content

Commit c5c8953

Browse files
committed
fixing pyarrow errors in control flow logic
1 parent aa707b1 commit c5c8953

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pandas/core/construction.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,14 @@ def sanitize_array(
566566
# extract ndarray or ExtensionArray, ensure we have no NumpyExtensionArray
567567
data = extract_array(data, extract_numpy=True, extract_range=True)
568568

569+
# GH#61026: when 2D input is allowed (e.g. DataFrame column assignment),
570+
# treat a (n, 1) numpy array as a 1D array of length n so downstream code
571+
# (including pyarrow-backed StringArray) always sees 1D.
572+
if allow_2d and isinstance(data, np.ndarray) and data.ndim == 2:
573+
rows, cols = data.shape
574+
if cols == 1:
575+
data = data[:, 0]
576+
569577
if isinstance(data, np.ndarray) and data.ndim == 0:
570578
if dtype is None:
571579
dtype = data.dtype
@@ -612,7 +620,7 @@ def sanitize_array(
612620

613621
if dtype is None:
614622
# GH#61026: special-case 2D+ object ndarrays when dtype is None.
615-
if data.dtype == object and data.ndim > 1:
623+
if allow_2d and data.dtype == object and data.ndim > 1:
616624
if data.ndim == 2 and data.shape[1] == 1:
617625
# allow assigning a (n, 1) object array to a single column.
618626
data = data[:, 0]

0 commit comments

Comments
 (0)