Skip to content

Commit bda2878

Browse files
PERF: improve construct_1d_object_array_from_listlike
1 parent a4fc97e commit bda2878

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

pandas/core/dtypes/cast.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@
8787

8888
if TYPE_CHECKING:
8989
from collections.abc import (
90+
Iterable,
9091
Sequence,
91-
Sized,
9292
)
9393

9494
from pandas._typing import (
@@ -1581,7 +1581,7 @@ def _maybe_box_and_unbox_datetimelike(value: Scalar, dtype: DtypeObj):
15811581
return _maybe_unbox_datetimelike(value, dtype)
15821582

15831583

1584-
def construct_1d_object_array_from_listlike(values: Sized) -> np.ndarray:
1584+
def construct_1d_object_array_from_listlike(values: Iterable) -> np.ndarray:
15851585
"""
15861586
Transform any list-like object in a 1-dimensional numpy array of object
15871587
dtype.
@@ -1602,7 +1602,8 @@ def construct_1d_object_array_from_listlike(values: Sized) -> np.ndarray:
16021602
# numpy will try to interpret nested lists as further dimensions, hence
16031603
# making a 1D array that contains list-likes is a bit tricky:
16041604
result = np.empty(len(values), dtype="object")
1605-
result[:] = values
1605+
for i, obj in enumerate(values):
1606+
result[i] = obj
16061607
return result
16071608

16081609

0 commit comments

Comments
 (0)