|
1 | 1 | # pylint: disable-msg=E1101,W0612
|
| 2 | +import pytest |
2 | 3 |
|
3 | 4 | import numpy as np
|
4 | 5 | import pandas as pd
|
@@ -317,37 +318,34 @@ def test_concat_axis1(self):
|
317 | 318 | assert isinstance(res, pd.SparseDataFrame)
|
318 | 319 | tm.assert_frame_equal(res.to_dense(), exp)
|
319 | 320 |
|
320 |
| - def test_concat_sparse_dense(self): |
321 |
| - sparse = self.dense1.to_sparse() |
322 |
| - |
| 321 | + @pytest.mark.parametrize('fill_value', [None, 0]) |
| 322 | + def test_concat_sparse_dense(self, fill_value): |
| 323 | + sparse = self.dense1.to_sparse(fill_value=fill_value) |
323 | 324 | res = pd.concat([sparse, self.dense2])
|
324 | 325 | exp = pd.concat([self.dense1, self.dense2])
|
325 |
| - assert isinstance(res, pd.SparseDataFrame) |
326 |
| - tm.assert_frame_equal(res.to_dense(), exp) |
327 |
| - |
328 |
| - res = pd.concat([self.dense2, sparse]) |
329 |
| - exp = pd.concat([self.dense2, self.dense1]) |
330 |
| - assert isinstance(res, pd.SparseDataFrame) |
331 |
| - tm.assert_frame_equal(res.to_dense(), exp) |
332 |
| - |
333 |
| - sparse = self.dense1.to_sparse(fill_value=0) |
334 | 326 |
|
335 |
| - res = pd.concat([sparse, self.dense2]) |
336 |
| - exp = pd.concat([self.dense1, self.dense2]) |
337 | 327 | assert isinstance(res, pd.SparseDataFrame)
|
338 | 328 | tm.assert_frame_equal(res.to_dense(), exp)
|
339 | 329 |
|
340 | 330 | res = pd.concat([self.dense2, sparse])
|
341 | 331 | exp = pd.concat([self.dense2, self.dense1])
|
| 332 | + |
342 | 333 | assert isinstance(res, pd.SparseDataFrame)
|
343 | 334 | tm.assert_frame_equal(res.to_dense(), exp)
|
344 | 335 |
|
345 | 336 | res = pd.concat([self.dense3, sparse], axis=1)
|
346 | 337 | exp = pd.concat([self.dense3, self.dense1], axis=1)
|
347 |
| - assert isinstance(res, pd.SparseDataFrame) |
| 338 | + # See GH18914 and #18686 for why this should be |
| 339 | + # A DataFrame |
| 340 | + assert isinstance(res, pd.DataFrame) |
| 341 | + for column in self.dense3.columns: |
| 342 | + tm.assert_series_equal(res[column], exp[column]) |
| 343 | + |
348 | 344 | tm.assert_frame_equal(res, exp)
|
349 | 345 |
|
350 | 346 | res = pd.concat([sparse, self.dense3], axis=1)
|
351 | 347 | exp = pd.concat([self.dense1, self.dense3], axis=1)
|
352 |
| - assert isinstance(res, pd.SparseDataFrame) |
| 348 | + assert isinstance(res, pd.DataFrame) |
| 349 | + for column in self.dense3.columns: |
| 350 | + tm.assert_series_equal(res[column], exp[column]) |
353 | 351 | tm.assert_frame_equal(res, exp)
|
0 commit comments