Skip to content

Commit c1cd33e

Browse files
committed
fixup! BUG: Made SparseDataFrame.fillna() fill all NaNs
1 parent 2974232 commit c1cd33e

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

pandas/tests/sparse/test_frame.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -1286,11 +1286,20 @@ def test_from_scipy_fillna(spmatrix):
12861286
sdf = pd.SparseDataFrame(spm).fillna(-1.0)
12871287

12881288
# 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
12921301

1293-
tm.assert_numpy_array_equal(sdf.values, expected.values)
1302+
tm.assert_sp_frame_equal(sdf, expected)
12941303

12951304

12961305
class TestSparseDataFrameArithmetic(object):

0 commit comments

Comments
 (0)