Skip to content

Commit

Permalink
fixup! BUG: Made SparseDataFrame.fillna() fill all NaNs
Browse files Browse the repository at this point in the history
  • Loading branch information
kernc committed Jul 13, 2017
1 parent 2974232 commit c1cd33e
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions pandas/tests/sparse/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1286,11 +1286,20 @@ def test_from_scipy_fillna(spmatrix):
sdf = pd.SparseDataFrame(spm).fillna(-1.0)

# Returning frame should fill all nan values with -1.0
expected = pd.SparseDataFrame([[1, -1, -1],
[-1, 1, -1],
[-1, -1, 1.]])
expected = pd.SparseDataFrame({
0: pd.SparseSeries([1., -1, -1]),
1: pd.SparseSeries([np.nan, 1, np.nan]),
2: pd.SparseSeries([np.nan, np.nan, 1]),
}, default_fill_value=-1)

# fill_value is expected to be what .fillna() above was called with
# We don't use -1 as initial fill_value in expected SparseSeries
# construction because this way we obtain "compressed" SparseArrays,
# avoiding having to construct them ourselves
for col in expected:
expected[col].fill_value = -1

tm.assert_numpy_array_equal(sdf.values, expected.values)
tm.assert_sp_frame_equal(sdf, expected)


class TestSparseDataFrameArithmetic(object):
Expand Down

0 comments on commit c1cd33e

Please sign in to comment.