Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/source/whatsnew/v3.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ Performance improvements
- Performance improvement in :meth:`DataFrame.loc` and :meth:`DataFrame.iloc`
setitem with a 2D list-of-lists value by avoiding a wasteful round-trip
through an intermediate object array (:issue:`64229`).
- Performance improvement in :meth:`Series.iloc` and :meth:`DataFrame.iloc`
when setting datetimelike values into object-dtype data with list-like
indexers (:issue:`64250`).

.. ---------------------------------------------------------------------------
.. _whatsnew_310.bug_fixes:
Expand Down
21 changes: 13 additions & 8 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@
ensure_wrapped_if_datetimelike,
extract_array,
)
from pandas.core.indexers import check_setitem_lengths
from pandas.core.indexers import (
check_setitem_lengths,
is_scalar_indexer,
length_of_indexer,
)
from pandas.core.indexes.base import get_values_for_csv

if TYPE_CHECKING:
Expand Down Expand Up @@ -1104,13 +1108,14 @@ def setitem(self, indexer, value) -> Block:
nb = self.coerce_to_target_dtype(value, raise_on_upcast=True)
return nb.setitem(indexer, value)
else:
if self.dtype == _dtype_obj:
# TODO: avoid having to construct values[indexer]
vi = values[indexer]
if lib.is_list_like(vi):
Comment thread
hyoj0942 marked this conversation as resolved.
# checking lib.is_scalar here fails on
# test_iloc_setitem_custom_object
casted = setitem_datetimelike_compat(values, len(vi), casted)
if self.dtype == _dtype_obj and not is_scalar_indexer(indexer, values.ndim):
if isinstance(
indexer, (ABCSeries, ABCIndex, np.ndarray, list, range, slice)
):
num_set = length_of_indexer(indexer, values)
else:
num_set = len(values[indexer])
casted = setitem_datetimelike_compat(values, num_set, casted)

self = self._maybe_copy(inplace=True)
values = cast("np.ndarray", self.values.T)
Expand Down
Loading