@@ -22,28 +22,45 @@ def snow_df():
2222 {"col1" : ["one" , "two" , "three" , pd .NA ], "col2" : ["abc" , "pqr" , "xyz" , None ]}
2323 )
2424
25+
2526@sql_count_checker (query_count = 4 )
26- def test_replace_mauricio ():
27+ def test_replace_mauricio_dataframe ():
2728 test_sdf = pd .DataFrame (
28- {"col1" : ["one" , "two" , "two" , "three" , "two" , "four" ], "col2" : ["abc" , "pqr" , "xyz" , None , "pqr" , "xyz" ,]}
29+ {
30+ "col1" : ["one" , "two" , "two" , "three" , "two" , "four" ],
31+ "col2" : [
32+ "abc" ,
33+ "pqr" ,
34+ "xyz" ,
35+ None ,
36+ "pqr" ,
37+ "xyz" ,
38+ ],
39+ }
2940 )
30- test_ndf = test_sdf .to_pandas ()
31- eval_snowpark_pandas_result (
32- test_sdf ,
33- test_ndf ,
34- lambda x : x
35- )
36- test_sdf ["col1" ] = test_sdf ["col1" ].replace (["two" ], ["a" ])
37- print (test_sdf )
38-
39- # Fails in native pandas HERE
40- test_ndf ["col1" ] = test_ndf ["col1" ].replace (["two" ], ["a" ])
41- print (test_ndf )
41+ test_ndf = test_sdf .to_pandas ()
42+ test_mdf = test_sdf .move_to ("Pandas" )
43+ assert test_mdf .get_backend () == "Pandas"
44+
4245 eval_snowpark_pandas_result (
43- test_sdf ,
44- test_ndf ,
45- lambda x : x
46+ test_sdf , test_ndf , lambda df : df ["col1" ].replace (["two" ], ["a" ])
4647 )
48+ snow_result = test_sdf ["col1" ].replace (["two" ], ["a" ])
49+ modin_result = test_mdf ["col1" ].replace (["two" ], ["a" ])
50+ assert modin_result .to_pandas ().equals (snow_result .to_pandas ())
51+
52+
53+ @sql_count_checker (query_count = 4 , join_count = 2 )
54+ def test_replace_mauricio_series ():
55+
56+ input_dict = pd .Series ({"a" : "apple" , "socks" : "socks are darned" , "b" : "bee" })
57+ input_dict_native = input_dict .to_pandas ()
58+ input_dict_pandas_modin = input_dict .move_to ("Pandas" )
59+ assert input_dict_pandas_modin .get_backend () == "Pandas"
60+ expected = input_dict_native ["socks" ].replace ("darned" , "clean" )
61+ assert input_dict ["socks" ].replace ("darned" , "clean" ) == expected
62+ assert input_dict_pandas_modin ["socks" ].replace ("darned" , "clean" ) == expected
63+
4764
4865@pytest .mark .parametrize (
4966 "to_replace, value" ,
0 commit comments