|
28 | 28 |
|
29 | 29 |
|
30 | 30 | class TestSparseDataFrame(tm.TestCase, SharedWithSparse):
|
31 |
| - |
32 | 31 | klass = SparseDataFrame
|
33 | 32 |
|
34 | 33 | def setUp(self):
|
@@ -758,7 +757,8 @@ def test_sparse_frame_fillna_limit(self):
|
758 | 757 | def test_rename(self):
|
759 | 758 | # just check this works
|
760 | 759 | renamed = self.frame.rename(index=str) # noqa
|
761 |
| - renamed = self.frame.rename(columns=lambda x: '%s%d' % (x, len(x))) # noqa |
| 760 | + renamed = self.frame.rename( |
| 761 | + columns=lambda x: '%s%d' % (x, len(x))) # noqa |
762 | 762 |
|
763 | 763 | def test_corr(self):
|
764 | 764 | res = self.frame.corr()
|
@@ -967,7 +967,6 @@ def _check(frame, orig):
|
967 | 967 | def test_shift(self):
|
968 | 968 |
|
969 | 969 | def _check(frame, orig):
|
970 |
| - |
971 | 970 | shifted = frame.shift(0)
|
972 | 971 | exp = orig.shift(0)
|
973 | 972 | tm.assert_frame_equal(shifted.to_dense(), exp)
|
@@ -1060,7 +1059,7 @@ def test_sparse_pow_issue(self):
|
1060 | 1059 | df = SparseDataFrame({'A': [nan, 0, 1]})
|
1061 | 1060 |
|
1062 | 1061 | # note that 2 ** df works fine, also df ** 1
|
1063 |
| - result = 1**df |
| 1062 | + result = 1 ** df |
1064 | 1063 |
|
1065 | 1064 | r1 = result.take([0], 1)['A']
|
1066 | 1065 | r2 = result['A']
|
@@ -1126,7 +1125,7 @@ def test_isnotnull(self):
|
1126 | 1125 | tm.assert_frame_equal(res.to_dense(), exp)
|
1127 | 1126 |
|
1128 | 1127 |
|
1129 |
| -@pytest.mark.parametrize('index', [None, list('ab')]) # noqa: F811 |
| 1128 | +@pytest.mark.parametrize('index', [None, list('ab')]) # noqa: F811 |
1130 | 1129 | @pytest.mark.parametrize('columns', [None, list('cd')])
|
1131 | 1130 | @pytest.mark.parametrize('fill_value', [None, 0, np.nan])
|
1132 | 1131 | @pytest.mark.parametrize('dtype', [bool, int, float, np.uint16])
|
@@ -1180,7 +1179,7 @@ def test_from_to_scipy(spmatrix, index, columns, fill_value, dtype):
|
1180 | 1179 | tm.assert_equal(sdf.to_coo().dtype, np.object_)
|
1181 | 1180 |
|
1182 | 1181 |
|
1183 |
| -@pytest.mark.parametrize('fill_value', [None, 0, np.nan]) # noqa: F811 |
| 1182 | +@pytest.mark.parametrize('fill_value', [None, 0, np.nan]) # noqa: F811 |
1184 | 1183 | def test_from_to_scipy_object(spmatrix, fill_value):
|
1185 | 1184 | # GH 4343
|
1186 | 1185 | dtype = object
|
@@ -1226,7 +1225,6 @@ def test_from_to_scipy_object(spmatrix, fill_value):
|
1226 | 1225 |
|
1227 | 1226 |
|
1228 | 1227 | class TestSparseDataFrameArithmetic(tm.TestCase):
|
1229 |
| - |
1230 | 1228 | def test_numeric_op_scalar(self):
|
1231 | 1229 | df = pd.DataFrame({'A': [nan, nan, 0, 1, ],
|
1232 | 1230 | 'B': [0, 1, 2, nan],
|
@@ -1255,7 +1253,6 @@ def test_comparison_op_scalar(self):
|
1255 | 1253 |
|
1256 | 1254 |
|
1257 | 1255 | class TestSparseDataFrameAnalytics(tm.TestCase):
|
1258 |
| - |
1259 | 1256 | def setUp(self):
|
1260 | 1257 | self.data = {'A': [nan, nan, nan, 0, 1, 2, 3, 4, 5, 6],
|
1261 | 1258 | 'B': [0, 1, 2, nan, nan, nan, 3, 4, 5, 6],
|
@@ -1299,3 +1296,12 @@ def test_numpy_func_call(self):
|
1299 | 1296 | 'std', 'min', 'max']
|
1300 | 1297 | for func in funcs:
|
1301 | 1298 | getattr(np, func)(self.frame)
|
| 1299 | + |
| 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