@@ -1236,6 +1236,7 @@ def test_from_to_scipy_object(spmatrix, fill_value):
1236
1236
tm .assert_sp_frame_equal (sdf_obj , expected )
1237
1237
tm .assert_frame_equal (sdf_obj .to_dense (), expected .to_dense ())
1238
1238
1239
+
1239
1240
# Assert spmatrices equal
1240
1241
assert dict (sdf .to_coo ().todok ()) == dict (spm .todok ())
1241
1242
@@ -1245,6 +1246,34 @@ def test_from_to_scipy_object(spmatrix, fill_value):
1245
1246
assert sdf .to_coo ().dtype == res_dtype
1246
1247
1247
1248
1249
+ def test_from_scipy_object_fillna (spmatrix ):
1250
+ columns = list ('cd' )
1251
+ index = list ('ab' )
1252
+ tm .skip_if_no_package ('scipy' , max_version = '0.19.0' )
1253
+
1254
+ # Explicitly convert one zero to np.nan
1255
+ arr = np .eye (2 )
1256
+ arr [1 , 0 ] = np .nan
1257
+ try :
1258
+ spm = spmatrix (arr )
1259
+ assert spm .dtype == arr .dtype
1260
+ except (TypeError , AssertionError ):
1261
+ # If conversion to sparse fails for this spmatrix type and arr.dtype,
1262
+ # then the combination is not currently supported in NumPy, so we
1263
+ # can just skip testing it thoroughly
1264
+ return
1265
+
1266
+ sdf = pd .SparseDataFrame (spm , index = index , columns = columns ).fillna (- 1.0 )
1267
+
1268
+ # Returning frame should fill all nan values with -1
1269
+ expected = pd .SparseDataFrame ({"c" : {"a" : 1.0 , "b" : - 1.0 }, "d" : {"a" : - 1.0 , "b" : 1.0 }})
1270
+
1271
+ # Assert frame is as expected
1272
+ sdf_obj = sdf .astype (object )
1273
+ tm .assert_sp_frame_equal (sdf_obj , expected )
1274
+ tm .assert_frame_equal (sdf_obj .to_dense (), expected .to_dense ())
1275
+
1276
+
1248
1277
class TestSparseDataFrameArithmetic (tm .TestCase ):
1249
1278
1250
1279
def test_numeric_op_scalar (self ):
0 commit comments