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