Skip to content

Commit ffe0791

Browse files
[2.3.x] COMPAT: fix construct_1d_object_array_from_listlike for older numpy (#60558)
COMPAT: fix construct_1d_object_array_from_listlike for older numpy
1 parent 0c6959d commit ffe0791

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

pandas/core/dtypes/cast.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1606,7 +1606,10 @@ def construct_1d_object_array_from_listlike(values: Collection) -> np.ndarray:
16061606
"""
16071607
# numpy will try to interpret nested lists as further dimensions in np.array(),
16081608
# hence explicitly making a 1D array using np.fromiter
1609-
return np.fromiter(values, dtype="object", count=len(values))
1609+
result = np.empty(len(values), dtype="object")
1610+
for i, obj in enumerate(values):
1611+
result[i] = obj
1612+
return result
16101613

16111614

16121615
def maybe_cast_to_integer_array(arr: list | np.ndarray, dtype: np.dtype) -> np.ndarray:

0 commit comments

Comments
 (0)