@@ -58,6 +58,11 @@ def engine_has_neg_frac(engine):
5858 return _engines [engine ].has_neg_frac
5959
6060
61+ @pytest .fixture (params = [1 , "cat" , [1 , 2 ], np .array ([]), (1 , 3 )])
62+ def invalid_target (request ):
63+ return request .param
64+
65+
6166def _eval_single_bin (lhs , cmp1 , rhs , engine ):
6267 c = _binary_ops_dict [cmp1 ]
6368 if engine_has_neg_frac (engine ):
@@ -1388,6 +1393,34 @@ def query_inplace(self):
13881393 df .query ('a == 2' , inplace = True )
13891394 assert_frame_equal (expected , df )
13901395
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+
13911424 def test_basic_period_index_boolean_expression (self ):
13921425 df = mkdf (2 , 2 , data_gen_f = f , c_idx_type = 'p' , r_idx_type = 'i' )
13931426
0 commit comments