@@ -1146,8 +1146,8 @@ def test_isnotnull(self):
11461146 tm .assert_frame_equal (res .to_dense (), exp )
11471147
11481148
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 ' )])
11511151@pytest .mark .parametrize ('fill_value' , [None , 0 , np .nan ])
11521152@pytest .mark .parametrize ('dtype' , [bool , int , float , np .uint16 ])
11531153def 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):
11561156
11571157 # Make one ndarray and from it one sparse matrix, both to be used for
11581158 # 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 )
11601162 try :
11611163 spm = spmatrix (arr )
11621164 assert spm .dtype == arr .dtype
@@ -1245,6 +1247,26 @@ def test_from_to_scipy_object(spmatrix, fill_value):
12451247 assert sdf .to_coo ().dtype == res_dtype
12461248
12471249
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+
12481270class TestSparseDataFrameArithmetic (object ):
12491271
12501272 def test_numeric_op_scalar (self ):
0 commit comments