Skip to content

Commit 6e4fe48

Browse files
committed
Make minor edits and add comments
1 parent 293df1f commit 6e4fe48

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

pandas/core/indexing.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,13 @@ def _get_setitem_indexer(self, key):
202202
def __setitem__(self, key, value):
203203
if isinstance(key, tuple):
204204
key = tuple(com.apply_if_callable(x, self.obj) for x in key)
205+
# if `key` is an index to multiple columns by name, add each column
206+
# if it does not already exist
205207
if (
206-
self.name == "loc"
207-
and len(key) > 1
208-
and is_list_like_indexer(key[1])
209-
and not isinstance(key[1], tuple)
208+
self.name == "loc" # column is indexed by name
209+
and len(key) >= 2 # key is at least 2-dimensional
210+
and is_list_like_indexer(key[1]) # key indexes multiple columns
211+
and not isinstance(self.obj._get_axis(1), ABCMultiIndex)
210212
and not com.is_bool_indexer(key[1])
211213
and all(is_hashable(k) for k in key[1])
212214
):

0 commit comments

Comments
 (0)