| @@ -1252,6 +1252,7 @@ def test_from_scipy_correct_ordering(spmatrix): |
|
|
| 1252 |
1252 |
tm.skip_if_no_package('scipy') |
| 1253 |
1253 |
|
| 1254 |
1254 |
arr = np.arange(1, 5).reshape(2, 2) |
|
1255 |
+ |
| 1255 |
1256 |
try: |
| 1256 |
1257 |
spm = spmatrix(arr) |
| 1257 |
1258 |
assert spm.dtype == arr.dtype |
| @@ -1267,6 +1268,33 @@ def test_from_scipy_correct_ordering(spmatrix): |
|
|
| 1267 |
1268 |
tm.assert_frame_equal(sdf.to_dense(), expected.to_dense()) |
| 1268 |
1269 |
|
| 1269 |
1270 |
|
|
1271 |
+def test_from_scipy_object_fillna(spmatrix): |
|
1272 |
+# GH 16112 |
|
1273 |
+tm.skip_if_no_package('scipy', max_version='0.19.0') |
|
1274 |
+ |
|
1275 |
+arr = np.eye(3) |
|
1276 |
+arr[1:, 0] = np.nan |
|
1277 |
+ |
|
1278 |
+try: |
|
1279 |
+spm = spmatrix(arr) |
|
1280 |
+assert spm.dtype == arr.dtype |
|
1281 |
+except (TypeError, AssertionError): |
|
1282 |
+# If conversion to sparse fails for this spmatrix type and arr.dtype, |
|
1283 |
+# then the combination is not currently supported in NumPy, so we |
|
1284 |
+# can just skip testing it thoroughly |
|
1285 |
+return |
|
1286 |
+ |
|
1287 |
+sdf = pd.SparseDataFrame(spm).fillna(-1.0) |
|
1288 |
+ |
|
1289 |
+# Returning frame should fill all nan values with -1.0 |
|
1290 |
+expected = pd.SparseDataFrame({0: {0: 1.0, 1: np.nan, 2: np.nan}, |
|
1291 |
+1: {0: np.nan, 1: 1.0, 2: np.nan}, |
|
1292 |
+2: {0: np.nan, 1: np.nan, 2: 1.0}} |
|
1293 |
+ ).fillna(-1.0) |
|
1294 |
+ |
|
1295 |
+tm.assert_frame_equal(sdf.to_dense(), expected.to_dense()) |
|
1296 |
+ |
|
1297 |
+ |
| 1270 |
1298 |
class TestSparseDataFrameArithmetic(object): |
| 1271 |
1299 |
|
| 1272 |
1300 |
def test_numeric_op_scalar(self): |