Skip to content

Commit 8c798c0

Browse files
mroeschkejreback
authored andcommitted
TST:Test to_sparse with nan dataframe (#10079) (#14913)
1 parent 8b98104 commit 8c798c0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pandas/sparse/tests/test_frame.py

+15
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,21 @@ def test_constructor_preserve_attr(self):
215215
self.assertEqual(df['x'].dtype, np.int64)
216216
self.assertEqual(df['x'].fill_value, 0)
217217

218+
def test_constructor_nan_dataframe(self):
219+
# GH 10079
220+
trains = np.arange(100)
221+
tresholds = [10, 20, 30, 40, 50, 60]
222+
tuples = [(i, j) for i in trains for j in tresholds]
223+
index = pd.MultiIndex.from_tuples(tuples,
224+
names=['trains', 'tresholds'])
225+
matrix = np.empty((len(index), len(trains)))
226+
matrix.fill(np.nan)
227+
df = pd.DataFrame(matrix, index=index, columns=trains, dtype=float)
228+
result = df.to_sparse()
229+
expected = pd.SparseDataFrame(matrix, index=index, columns=trains,
230+
dtype=float)
231+
tm.assert_sp_frame_equal(result, expected)
232+
218233
def test_dtypes(self):
219234
df = DataFrame(np.random.randn(10000, 4))
220235
df.ix[:9998] = np.nan

0 commit comments

Comments
 (0)