@@ -57,13 +57,24 @@ def test_series_replace_all(gsr, to_replace, value):
57
57
else :
58
58
pd_value = value
59
59
60
- actual = gsr .replace (to_replace = gd_to_replace , value = gd_value )
61
- if pd_value is None :
62
- # TODO: Remove this workaround once cudf
63
- # introduces `no_default` values
64
- expected = psr .replace (to_replace = pd_to_replace )
65
- else :
66
- expected = psr .replace (to_replace = pd_to_replace , value = pd_value )
60
+ with expect_warning_if (
61
+ isinstance (gsr .dtype , cudf .CategoricalDtype )
62
+ and isinstance (gd_to_replace , str )
63
+ and gd_to_replace == "one"
64
+ ):
65
+ actual = gsr .replace (to_replace = gd_to_replace , value = gd_value )
66
+ with expect_warning_if (
67
+ PANDAS_GE_220
68
+ and isinstance (gsr .dtype , cudf .CategoricalDtype )
69
+ and isinstance (gd_to_replace , str )
70
+ and gd_to_replace == "one"
71
+ ):
72
+ if pd_value is None :
73
+ # TODO: Remove this workaround once cudf
74
+ # introduces `no_default` values
75
+ expected = psr .replace (to_replace = pd_to_replace )
76
+ else :
77
+ expected = psr .replace (to_replace = pd_to_replace , value = pd_value )
67
78
68
79
assert_eq (
69
80
expected .sort_values ().reset_index (drop = True ),
@@ -82,16 +93,19 @@ def test_series_replace():
82
93
83
94
# Categorical
84
95
psr3 = pd .Series (["one" , "two" , "three" ], dtype = "category" )
85
- psr4 = psr3 .replace ("one" , "two" )
96
+ with expect_warning_if (PANDAS_GE_220 ):
97
+ psr4 = psr3 .replace ("one" , "two" )
86
98
sr3 = cudf .from_pandas (psr3 )
87
- sr4 = sr3 .replace ("one" , "two" )
99
+ with pytest .warns (FutureWarning ):
100
+ sr4 = sr3 .replace ("one" , "two" )
88
101
assert_eq (
89
102
psr4 .sort_values ().reset_index (drop = True ),
90
103
sr4 .sort_values ().reset_index (drop = True ),
91
104
)
92
-
93
- psr5 = psr3 .replace ("one" , "five" )
94
- sr5 = sr3 .replace ("one" , "five" )
105
+ with expect_warning_if (PANDAS_GE_220 ):
106
+ psr5 = psr3 .replace ("one" , "five" )
107
+ with pytest .warns (FutureWarning ):
108
+ sr5 = sr3 .replace ("one" , "five" )
95
109
96
110
assert_eq (psr5 , sr5 )
97
111
@@ -236,11 +250,26 @@ def test_dataframe_replace(df, to_replace, value):
236
250
else :
237
251
gd_to_replace = to_replace
238
252
239
- if pd_value is None :
240
- expected = pdf .replace (to_replace = pd_to_replace )
241
- else :
242
- expected = pdf .replace (to_replace = pd_to_replace , value = pd_value )
243
- actual = gdf .replace (to_replace = gd_to_replace , value = gd_value )
253
+ with expect_warning_if (
254
+ PANDAS_GE_220
255
+ and isinstance (df ["a" ].dtype , cudf .CategoricalDtype )
256
+ and isinstance (to_replace , str )
257
+ and to_replace == "two"
258
+ and isinstance (value , str )
259
+ and value == "three"
260
+ ):
261
+ if pd_value is None :
262
+ expected = pdf .replace (to_replace = pd_to_replace )
263
+ else :
264
+ expected = pdf .replace (to_replace = pd_to_replace , value = pd_value )
265
+ with expect_warning_if (
266
+ isinstance (df ["a" ].dtype , cudf .CategoricalDtype )
267
+ and isinstance (to_replace , str )
268
+ and to_replace == "two"
269
+ and isinstance (value , str )
270
+ and value == "three"
271
+ ):
272
+ actual = gdf .replace (to_replace = gd_to_replace , value = gd_value )
244
273
245
274
expected_sorted = expected .sort_values (by = list (expected .columns ), axis = 0 )
246
275
actual_sorted = actual .sort_values (by = list (actual .columns ), axis = 0 )
@@ -1342,7 +1371,8 @@ def test_series_replace_errors():
1342
1371
],
1343
1372
)
1344
1373
def test_replace_nulls (gsr , old , new , expected ):
1345
- actual = gsr .replace (old , new )
1374
+ with expect_warning_if (isinstance (gsr .dtype , cudf .CategoricalDtype )):
1375
+ actual = gsr .replace (old , new )
1346
1376
assert_eq (
1347
1377
expected .sort_values ().reset_index (drop = True ),
1348
1378
actual .sort_values ().reset_index (drop = True ),
0 commit comments