@@ -1146,8 +1146,8 @@ def test_isnotnull(self):
1146
1146
tm .assert_frame_equal (res .to_dense (), exp )
1147
1147
1148
1148
1149
- @pytest .mark .parametrize ('index' , [None , list ('ab ' )]) # noqa: F811
1150
- @pytest .mark .parametrize ('columns' , [None , list ('cd ' )])
1149
+ @pytest .mark .parametrize ('index' , [None , list ('abc ' )]) # noqa: F811
1150
+ @pytest .mark .parametrize ('columns' , [None , list ('def ' )])
1151
1151
@pytest .mark .parametrize ('fill_value' , [None , 0 , np .nan ])
1152
1152
@pytest .mark .parametrize ('dtype' , [bool , int , float , np .uint16 ])
1153
1153
def test_from_to_scipy (spmatrix , index , columns , fill_value , dtype ):
@@ -1156,7 +1156,9 @@ def test_from_to_scipy(spmatrix, index, columns, fill_value, dtype):
1156
1156
1157
1157
# Make one ndarray and from it one sparse matrix, both to be used for
1158
1158
# constructing frames and comparing results
1159
- arr = np .eye (2 , dtype = dtype )
1159
+ arr = np .eye (3 , dtype = dtype )
1160
+ # GH 16179
1161
+ arr [0 , 1 ] = dtype (2 )
1160
1162
try :
1161
1163
spm = spmatrix (arr )
1162
1164
assert spm .dtype == arr .dtype
@@ -1245,6 +1247,26 @@ def test_from_to_scipy_object(spmatrix, fill_value):
1245
1247
assert sdf .to_coo ().dtype == res_dtype
1246
1248
1247
1249
1250
+ def test_from_scipy_correct_ordering (spmatrix ):
1251
+ # GH 16179
1252
+ tm .skip_if_no_package ('scipy' )
1253
+
1254
+ arr = np .arange (1 , 5 ).reshape (2 , 2 )
1255
+ try :
1256
+ spm = spmatrix (arr )
1257
+ assert spm .dtype == arr .dtype
1258
+ except (TypeError , AssertionError ):
1259
+ # If conversion to sparse fails for this spmatrix type and arr.dtype,
1260
+ # then the combination is not currently supported in NumPy, so we
1261
+ # can just skip testing it thoroughly
1262
+ return
1263
+
1264
+ sdf = pd .SparseDataFrame (spm )
1265
+ expected = pd .SparseDataFrame (arr )
1266
+ tm .assert_sp_frame_equal (sdf , expected )
1267
+ tm .assert_frame_equal (sdf .to_dense (), expected .to_dense ())
1268
+
1269
+
1248
1270
class TestSparseDataFrameArithmetic (object ):
1249
1271
1250
1272
def test_numeric_op_scalar (self ):
0 commit comments