@@ -373,23 +373,20 @@ def apply(self: T, f, align_keys=None, **kwargs) -> T:
373
373
374
374
self ._consolidate_inplace ()
375
375
376
- align_copy = False
377
- if f == "where" :
378
- align_copy = True
379
-
380
376
aligned_args = {k : kwargs [k ] for k in align_keys }
381
377
382
378
for b in self .blocks :
383
379
384
380
if aligned_args :
385
- b_items = self .items [b .mgr_locs .indexer ]
386
381
387
382
for k , obj in aligned_args .items ():
388
383
if isinstance (obj , (ABCSeries , ABCDataFrame )):
389
- axis = obj ._info_axis_number
390
- kwargs [k ] = obj .reindex (
391
- b_items , axis = axis , copy = align_copy
392
- )._values
384
+ # The caller is responsible for ensuring that
385
+ # obj.axes[-1].equals(self.items)
386
+ if obj .ndim == 1 :
387
+ kwargs [k ] = obj .iloc [b .mgr_locs .indexer ]._values
388
+ else :
389
+ kwargs [k ] = obj .iloc [:, b .mgr_locs .indexer ]._values
393
390
else :
394
391
# otherwise we have an ndarray
395
392
kwargs [k ] = obj [b .mgr_locs .indexer ]
@@ -1125,6 +1122,7 @@ def insert(self, loc: int, item: Label, value, allow_duplicates: bool = False):
1125
1122
new_axis = self .items .insert (loc , item )
1126
1123
1127
1124
if value .ndim == self .ndim - 1 and not is_extension_array_dtype (value .dtype ):
1125
+ # TODO(EA2D): special case not needed with 2D EAs
1128
1126
value = _safe_reshape (value , (1 ,) + value .shape )
1129
1127
1130
1128
block = make_block (values = value , ndim = self .ndim , placement = slice (loc , loc + 1 ))
0 commit comments