Skip to content

Commit

Permalink
COMPAT: fix construct_1d_object_array_from_listlike for older numpy
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche committed Dec 13, 2024
1 parent 9052c9e commit 6150439
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 6150439

Please sign in to comment.