Skip to content

Commit

Permalink
Added test to check if issue pandas-dev#16112 is fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
kristopheryahoo committed Apr 29, 2017
1 parent 075eca1 commit 9aae408
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pandas/tests/sparse/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,7 @@ def test_from_to_scipy_object(spmatrix, fill_value):
tm.assert_sp_frame_equal(sdf_obj, expected)
tm.assert_frame_equal(sdf_obj.to_dense(), expected.to_dense())


# Assert spmatrices equal
assert dict(sdf.to_coo().todok()) == dict(spm.todok())

Expand All @@ -1245,6 +1246,34 @@ def test_from_to_scipy_object(spmatrix, fill_value):
assert sdf.to_coo().dtype == res_dtype


def test_from_scipy_object_fillna(spmatrix):
columns = list('cd')
index = list('ab')
tm.skip_if_no_package('scipy', max_version='0.19.0')

# Explicitly convert one zero to np.nan
arr = np.eye(2)
arr[1, 0] = np.nan
try:
spm = spmatrix(arr)
assert spm.dtype == arr.dtype
except (TypeError, AssertionError):
# If conversion to sparse fails for this spmatrix type and arr.dtype,
# then the combination is not currently supported in NumPy, so we
# can just skip testing it thoroughly
return

sdf = pd.SparseDataFrame(spm, index=index, columns=columns).fillna(-1.0)

# Returning frame should fill all nan values with -1
expected = pd.SparseDataFrame({"c": {"a": 1.0, "b": -1.0}, "d": {"a": -1.0, "b": 1.0}})

# Assert frame is as expected
sdf_obj = sdf.astype(object)
tm.assert_sp_frame_equal(sdf_obj, expected)
tm.assert_frame_equal(sdf_obj.to_dense(), expected.to_dense())


class TestSparseDataFrameArithmetic(tm.TestCase):

def test_numeric_op_scalar(self):
Expand Down

0 comments on commit 9aae408

Please sign in to comment.