Skip to content

Commit 1009a7d

Browse files
PERF: indexing (#43274)
* PERF: indexing.InsertColumns.time_assign_with_setitem * added whatsnew * more descriptive whatsnew * rectified whatsnew * added PR ref in whatsnew * clear whatsnew * suggested change * added blank line
1 parent 7e05bcd commit 1009a7d

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
@@ -3622,9 +3622,11 @@ def __setitem__(self, key, value):
36223622
self._setitem_array(key, value)
36233623
elif isinstance(value, DataFrame):
36243624
self._set_item_frame_value(key, value)
3625-
elif is_list_like(value) and 1 < len(
3626-
self.columns.get_indexer_for([key])
3627-
) == len(value):
3625+
elif (
3626+
is_list_like(value)
3627+
and not self.columns.is_unique
3628+
and 1 < len(self.columns.get_indexer_for([key])) == len(value)
3629+
):
36283630
# Column to set is duplicated
36293631
self._setitem_array([key], value)
36303632
else:

0 commit comments

Comments
 (0)