@@ -236,6 +236,18 @@ def test_constructor_nan_dataframe(self):
236
236
dtype = float )
237
237
tm .assert_sp_frame_equal (result , expected )
238
238
239
+ def test_type_coercion_at_construction (self ):
240
+ # GH 15682
241
+ result = pd .SparseDataFrame (
242
+ {'a' : [1 , 0 , 0 ], 'b' : [0 , 1 , 0 ], 'c' : [0 , 0 , 1 ]}, dtype = 'uint8' ,
243
+ default_fill_value = 0 )
244
+ expected = pd .SparseDataFrame (
245
+ {'a' : pd .SparseSeries ([1 , 0 , 0 ], dtype = 'uint8' ),
246
+ 'b' : pd .SparseSeries ([0 , 1 , 0 ], dtype = 'uint8' ),
247
+ 'c' : pd .SparseSeries ([0 , 0 , 1 ], dtype = 'uint8' )},
248
+ default_fill_value = 0 )
249
+ tm .assert_sp_frame_equal (result , expected )
250
+
239
251
def test_dtypes (self ):
240
252
df = DataFrame (np .random .randn (10000 , 4 ))
241
253
df .loc [:9998 ] = np .nan
@@ -756,8 +768,8 @@ def test_sparse_frame_fillna_limit(self):
756
768
757
769
def test_rename (self ):
758
770
# just check this works
759
- renamed = self .frame .rename (index = str ) # noqa
760
- renamed = self .frame .rename (
771
+ rename = self .frame .rename (index = str ) # noqa
772
+ rename = self .frame .rename (
761
773
columns = lambda x : '%s%d' % (x , len (x ))) # noqa
762
774
763
775
def test_corr (self ):
@@ -1225,6 +1237,7 @@ def test_from_to_scipy_object(spmatrix, fill_value):
1225
1237
1226
1238
1227
1239
class TestSparseDataFrameArithmetic (tm .TestCase ):
1240
+
1228
1241
def test_numeric_op_scalar (self ):
1229
1242
df = pd .DataFrame ({'A' : [nan , nan , 0 , 1 , ],
1230
1243
'B' : [0 , 1 , 2 , nan ],
@@ -1297,11 +1310,3 @@ def test_numpy_func_call(self):
1297
1310
for func in funcs :
1298
1311
getattr (np , func )(self .frame )
1299
1312
1300
- def test_type_coercion_at_construction (self ):
1301
- # GH 15682
1302
- df = pd .SparseDataFrame (
1303
- {'a' : [1 , 0 , 0 ], 'b' : [0 , 1 , 0 ], 'c' : [0 , 0 , 1 ]}, dtype = 'uint8' ,
1304
- default_fill_value = 0 )
1305
- result = df .dtypes [0 ]
1306
- expected = np .dtype ('uint8' )
1307
- assert result == expected
0 commit comments