@@ -2530,10 +2530,10 @@ def __setitem__(self, key, value):
2530
2530
if indexer is not None :
2531
2531
return self ._setitem_slice (indexer , value )
2532
2532
2533
- if isinstance (key , (Series , np .ndarray , list , Index )):
2534
- self ._setitem_array (key , value )
2535
- elif isinstance (key , DataFrame ):
2533
+ if isinstance (key , DataFrame ) or getattr (key , 'ndim' , None ) == 2 :
2536
2534
self ._setitem_frame (key , value )
2535
+ elif isinstance (key , (Series , np .ndarray , list , Index )):
2536
+ self ._setitem_array (key , value )
2537
2537
else :
2538
2538
# set column
2539
2539
self ._set_item (key , value )
@@ -2566,8 +2566,17 @@ def _setitem_array(self, key, value):
2566
2566
def _setitem_frame (self , key , value ):
2567
2567
# support boolean setting with DataFrame input, e.g.
2568
2568
# df[df > df2] = 0
2569
+ if isinstance (key , np .ndarray ):
2570
+ if key .shape != self .shape :
2571
+ raise ValueError (
2572
+ 'Array conditional must be same shape as self'
2573
+ )
2574
+ key = self ._constructor (key , ** self ._construct_axes_dict ())
2575
+
2569
2576
if key .values .size and not is_bool_dtype (key .values ):
2570
- raise TypeError ('Must pass DataFrame with boolean values only' )
2577
+ raise TypeError (
2578
+ 'Must pass DataFrame or 2-d ndarray with boolean values only'
2579
+ )
2571
2580
2572
2581
self ._check_inplace_setting (value )
2573
2582
self ._check_setitem_copy ()
0 commit comments