fixup! BUG: Made SparseDataFrame.fillna() fill all NaNs · rs2/pandas@c1cd33e (original) (raw)

Original file line number Diff line number Diff line change
@@ -1286,11 +1286,20 @@ def test_from_scipy_fillna(spmatrix):
1286 1286 sdf = pd.SparseDataFrame(spm).fillna(-1.0)
1287 1287
1288 1288 # Returning frame should fill all nan values with -1.0
1289 -expected = pd.SparseDataFrame([[1, -1, -1],
1290 - [-1, 1, -1],
1291 - [-1, -1, 1.]])
1289 +expected = pd.SparseDataFrame({
1290 +0: pd.SparseSeries([1., -1, -1]),
1291 +1: pd.SparseSeries([np.nan, 1, np.nan]),
1292 +2: pd.SparseSeries([np.nan, np.nan, 1]),
1293 + }, default_fill_value=-1)
1294 +
1295 +# fill_value is expected to be what .fillna() above was called with
1296 +# We don't use -1 as initial fill_value in expected SparseSeries
1297 +# construction because this way we obtain "compressed" SparseArrays,
1298 +# avoiding having to construct them ourselves
1299 +for col in expected:
1300 +expected[col].fill_value = -1
1292 1301
1293 -tm.assert_numpy_array_equal(sdf.values, expected.values)
1302 +tm.assert_sp_frame_equal(sdf, expected)
1294 1303
1295 1304
1296 1305 class TestSparseDataFrameArithmetic(object):