@@ -1198,24 +1198,23 @@ def test_dataframe_repr_html(df) -> None:
11981198 assert output .replace (" " , "" ) == ref_html .replace (" " , "" )
11991199
12001200
1201-
12021201def test_fill_null (df ):
12031202 # Test filling nulls with integer value
1204- df_with_nulls = df .with_column ("d" , literal (None ).cast (pa .int64 ()))
1203+ df_with_nulls = df .with_column ("d" , literal (None ).cast (pa .int64 ()))
12051204 df_filled = df_with_nulls .fill_null (0 )
12061205 result = df_filled .to_pydict ()
12071206 assert result ["d" ] == [0 , 0 , 0 ]
12081207
12091208 # Test filling nulls with string value
1210- df_with_nulls = df .with_column ("d" , literal (None ).cast (pa .string ()))
1209+ df_with_nulls = df .with_column ("d" , literal (None ).cast (pa .string ()))
12111210 df_filled = df_with_nulls .fill_null ("missing" )
12121211 result = df_filled .to_pydict ()
1213- assert result ["e " ] == ["missing" , "missing" , "missing" ]
1212+ assert result ["d " ] == ["missing" , "missing" , "missing" ]
12141213
12151214 # Test filling nulls with subset of columns
12161215 df_with_nulls = df .with_columns (
1217- literal (None ).alias ("d" ),
1218- literal (None ).alias ("e" ),
1216+ literal (None ).cast ( pa . int64 ()). alias ("d" ),
1217+ literal (None ).cast ( pa . string ()). alias ("e" ),
12191218 )
12201219 df_filled = df_with_nulls .fill_null ("missing" , subset = ["e" ])
12211220 result = df_filled .to_pydict ()
@@ -1230,8 +1229,8 @@ def test_fill_null(df):
12301229
12311230 # Test filling nulls with value that can be cast to some columns but not others
12321231 df_with_nulls = df .with_columns (
1233- literal (None ).alias ("d" ),
1234- literal (None ).alias ("e" ),
1232+ literal (None ).alias ("d" ). cast ( pa . int64 ()) ,
1233+ literal (None ).alias ("e" ). cast ( pa . string ()) ,
12351234 )
12361235 df_filled = df_with_nulls .fill_null (0 )
12371236 result = df_filled .to_pydict ()
@@ -1240,8 +1239,8 @@ def test_fill_null(df):
12401239
12411240 # Test filling nulls with subset of columns where some casts fail
12421241 df_with_nulls = df .with_columns (
1243- literal (None ).alias ("d" ),
1244- literal (None ).alias ("e" ),
1242+ literal (None ).alias ("d" ). cast ( pa . int64 ()) ,
1243+ literal (None ).alias ("e" ). cast ( pa . string ()) ,
12451244 )
12461245 df_filled = df_with_nulls .fill_null (0 , subset = ["d" , "e" ])
12471246 result = df_filled .to_pydict ()
@@ -1250,8 +1249,8 @@ def test_fill_null(df):
12501249
12511250 # Test filling nulls with subset of columns where all casts succeed
12521251 df_with_nulls = df .with_columns (
1253- literal (None ).alias ("d" ),
1254- literal (None ).alias ("e" ),
1252+ literal (None ).alias ("d" ). cast ( pa . int64 ()) ,
1253+ literal (None ).alias ("e" ). cast ( pa . string ()) ,
12551254 )
12561255 df_filled = df_with_nulls .fill_null ("missing" , subset = ["e" ])
12571256 result = df_filled .to_pydict ()
@@ -1260,8 +1259,8 @@ def test_fill_null(df):
12601259
12611260 # Test filling nulls with subset of columns where some columns do not exist
12621261 df_with_nulls = df .with_columns (
1263- literal (None ).alias ("d" ),
1264- literal (None ).alias ("e" ),
1262+ literal (None ).alias ("d" ). cast ( pa . int64 ()) ,
1263+ literal (None ).alias ("e" ). cast ( pa . string ()) ,
12651264 )
12661265 with pytest .raises (ValueError , match = "Column 'f' not found in DataFrame" ):
1267- df_with_nulls .fill_null ("missing" , subset = ["e" , "f" ])
1266+ df_with_nulls .fill_null ("missing" , subset = ["e" , "f" ])
0 commit comments