@@ -166,37 +166,7 @@ def _get_loc(self, key: int, axis: int):
166
166
def _slice (self , obj , axis : int , kind = None ):
167
167
return self .obj ._slice (obj , axis = axis , kind = kind )
168
168
169
- def _ensure_listlike_indexer (self , key , axis : int ):
170
- """
171
- Ensure that a list-like of keys are all present by adding them if they
172
- do not already exist.
173
-
174
- Parameters
175
- ----------
176
- key : list-like
177
- Target labels
178
- axis : int
179
- Dimension on which the indexing is being made
180
- """
181
- if not isinstance (self .obj ._get_axis (axis ), ABCMultiIndex ) and all (
182
- is_hashable (k ) for k in key
183
- ):
184
- for k in key :
185
- try :
186
- self .obj [k ]
187
- except KeyError :
188
- self .obj [k ] = np .nan
189
-
190
169
def _get_setitem_indexer (self , key ):
191
- if (
192
- self .name == "loc" # column is indexed by name
193
- and isinstance (key , tuple )
194
- and len (key ) >= 2 # key is at least 2-dimensional
195
- and is_list_like_indexer (key [1 ]) # key indexes multiple columns
196
- and not com .is_bool_indexer (key [1 ])
197
- ):
198
- self ._ensure_listlike_indexer (key [1 ], axis = 1 )
199
-
200
170
if self .axis is not None :
201
171
return self ._convert_tuple (key )
202
172
@@ -1841,6 +1811,36 @@ def _getitem_axis(self, key, axis: int):
1841
1811
self ._validate_key (key , axis )
1842
1812
return self ._get_label (key , axis = axis )
1843
1813
1814
+ def _ensure_listlike_indexer (self , key , axis : int ):
1815
+ """
1816
+ Ensure that a list-like of keys are all present by adding them if they
1817
+ do not already exist.
1818
+
1819
+ Parameters
1820
+ ----------
1821
+ key : list-like
1822
+ Target labels
1823
+ axis : int
1824
+ Dimension on which the indexing is being made
1825
+ """
1826
+ if not isinstance (self .obj ._get_axis (axis ), ABCMultiIndex ) and all (
1827
+ is_hashable (k ) for k in key
1828
+ ):
1829
+ for k in key :
1830
+ try :
1831
+ self .obj [k ]
1832
+ except KeyError :
1833
+ self .obj [k ] = np .nan
1834
+
1835
+ def _get_setitem_indexer (self , key ):
1836
+ if (
1837
+ isinstance (key , tuple )
1838
+ and len (key ) >= 2 # key is at least 2-dimensional
1839
+ and is_list_like_indexer (key [1 ]) # key indexes multiple columns
1840
+ and not com .is_bool_indexer (key [1 ])
1841
+ ):
1842
+ self ._ensure_listlike_indexer (key [1 ], axis = 1 )
1843
+ return super ()._get_setitem_indexer (key )
1844
1844
1845
1845
class _iLocIndexer (_LocationIndexer ):
1846
1846
"""
0 commit comments