Skip to content

Commit

Permalink
[2.3.x] COMPAT: fix construct_1d_object_array_from_listlike for older…
Browse files Browse the repository at this point in the history
… numpy (#60558)

COMPAT: fix construct_1d_object_array_from_listlike for older numpy
  • Loading branch information
jorisvandenbossche authored Dec 13, 2024
1 parent 0c6959d commit ffe0791
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pandas/core/dtypes/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -1606,7 +1606,10 @@ def construct_1d_object_array_from_listlike(values: Collection) -> np.ndarray:
"""
# numpy will try to interpret nested lists as further dimensions in np.array(),
# hence explicitly making a 1D array using np.fromiter
return np.fromiter(values, dtype="object", count=len(values))
result = np.empty(len(values), dtype="object")
for i, obj in enumerate(values):
result[i] = obj
return result


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

0 comments on commit ffe0791

Please sign in to comment.