We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 293df1f commit 6e4fe48Copy full SHA for 6e4fe48
pandas/core/indexing.py
@@ -202,11 +202,13 @@ def _get_setitem_indexer(self, key):
202
def __setitem__(self, key, value):
203
if isinstance(key, tuple):
204
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
207
if (
- self.name == "loc"
- and len(key) > 1
208
- and is_list_like_indexer(key[1])
209
- and not isinstance(key[1], tuple)
+ self.name == "loc" # column is indexed by name
+ 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)
212
and not com.is_bool_indexer(key[1])
213
and all(is_hashable(k) for k in key[1])
214
):
0 commit comments