@@ -1297,11 +1297,21 @@ def test_fill_nan(df):
1297
1297
df_with_nans = df .with_columns (
1298
1298
literal (float ("nan" )).alias ("d" ).cast (pa .float64 ()),
1299
1299
literal (float ("nan" )).alias ("e" ).cast (pa .float64 ()),
1300
+ literal ("abc" ).alias ("f" ).cast (pa .string ()), # non-numeric column
1300
1301
)
1301
- df_filled = df_with_nans .fill_nan (0 , subset = ["d" , "e" ])
1302
+ df_filled = df_with_nans .fill_nan (0 , subset = ["d" , "e" , "f" ])
1302
1303
result = df_filled .to_pydict ()
1303
- assert result ["d" ] == [0 , 0 , 0 ]
1304
- assert result ["e" ] == [0 , 0 , 0 ]
1304
+ assert result ["d" ] == [0 , 0 , 0 ] # succeeds
1305
+ assert result ["e" ] == [0 , 0 , 0 ] # succeeds
1306
+ assert result ["f" ] == ["abc" , "abc" , "abc" ] # skipped because not numeric
1307
+
1308
+ # Test filling NaNs fails on non-numeric columns
1309
+ df_with_mixed = df .with_columns (
1310
+ literal (float ("nan" )).alias ("d" ).cast (pa .float64 ()),
1311
+ literal ("abc" ).alias ("e" ).cast (pa .string ()),
1312
+ )
1313
+ with pytest .raises (ValueError , match = "Column 'e' is not a numeric column" ):
1314
+ df_with_mixed .fill_nan (0 , subset = ["d" , "e" ])
1305
1315
1306
1316
# Test filling NaNs with subset of columns where all casts succeed
1307
1317
df_with_nans = df .with_columns (
0 commit comments