@@ -58,6 +58,11 @@ def engine_has_neg_frac(engine):
58
58
return _engines [engine ].has_neg_frac
59
59
60
60
61
+ @pytest .fixture (params = [1 , "cat" , [1 , 2 ], np .array ([]), (1 , 3 )])
62
+ def invalid_target (request ):
63
+ return request .param
64
+
65
+
61
66
def _eval_single_bin (lhs , cmp1 , rhs , engine ):
62
67
c = _binary_ops_dict [cmp1 ]
63
68
if engine_has_neg_frac (engine ):
@@ -1388,6 +1393,34 @@ def query_inplace(self):
1388
1393
df .query ('a == 2' , inplace = True )
1389
1394
assert_frame_equal (expected , df )
1390
1395
1396
+ df = {}
1397
+ expected = {"a" : 3 }
1398
+
1399
+ self .eval ("a = 1 + 2" , target = df , inplace = True )
1400
+ tm .assert_dict_equal (df , expected )
1401
+
1402
+ def cannot_item_assign (self , invalid_target ):
1403
+ msg = "Cannot assign expression output to target"
1404
+ expr = "a = 1 + 2"
1405
+
1406
+ with tm .assert_raises_regex (ValueError , msg ):
1407
+ self .eval (expr , target = invalid_target , inplace = True )
1408
+
1409
+ def cannot_copy_item (self , invalid_target ):
1410
+ msg = "Cannot return a copy of the target"
1411
+ expr = "a = 1 + 2"
1412
+
1413
+ with tm .assert_raises_regex (ValueError , msg ):
1414
+ self .eval (expr , target = invalid_target , inplace = False )
1415
+
1416
+ def ignore_invalid_target_no_assignment (self , invalid_target ):
1417
+ # No Exception should be raised because we are
1418
+ # not performing item assignment in this test.
1419
+ expr = "1 + 2"
1420
+
1421
+ assert self .eval (expr , target = invalid_target , inplace = False ) == 3
1422
+ assert self .eval (expr , target = invalid_target , inplace = True ) is None
1423
+
1391
1424
def test_basic_period_index_boolean_expression (self ):
1392
1425
df = mkdf (2 , 2 , data_gen_f = f , c_idx_type = 'p' , r_idx_type = 'i' )
1393
1426
0 commit comments