Skip to content

Commit 9fbb61f

Browse files
Backport PR #43274: PERF: indexing (#43303)
Co-authored-by: Shoham Debnath <[email protected]>
1 parent 3cc9587 commit 9fbb61f

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

doc/source/whatsnew/v1.3.3.rst

+10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ Fixed regressions
2121

2222
.. ---------------------------------------------------------------------------
2323
24+
.. _whatsnew_133.performance:
25+
26+
Performance improvements
27+
~~~~~~~~~~~~~~~~~~~~~~~~
28+
- Performance improvement for :meth:`DataFrame.__setitem__` when the key or value is not a :class:`DataFrame`, or key is not list-like (:issue:`43274`)
29+
-
30+
-
31+
32+
.. ---------------------------------------------------------------------------
33+
2434
.. _whatsnew_133.bug_fixes:
2535

2636
Bug fixes

pandas/core/frame.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -3597,9 +3597,11 @@ def __setitem__(self, key, value):
35973597
self._setitem_array(key, value)
35983598
elif isinstance(value, DataFrame):
35993599
self._set_item_frame_value(key, value)
3600-
elif is_list_like(value) and 1 < len(
3601-
self.columns.get_indexer_for([key])
3602-
) == len(value):
3600+
elif (
3601+
is_list_like(value)
3602+
and not self.columns.is_unique
3603+
and 1 < len(self.columns.get_indexer_for([key])) == len(value)
3604+
):
36033605
# Column to set is duplicated
36043606
self._setitem_array([key], value)
36053607
else:

0 commit comments

Comments
 (0)