Skip to content

Commit 6fc6369

Browse files
committed
Add more specific tests
1 parent 05a0717 commit 6fc6369

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

pandas/core/dtypes/concat.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,13 @@ def _get_frame_result_type(result, objs):
9292
if all blocks are SparseBlock, return SparseDataFrame
9393
otherwise, return 1st obj
9494
"""
95+
96+
from pandas.core.sparse.api import SparseDataFrame
97+
9598
if result.blocks and all(b.is_sparse for b in result.blocks):
96-
from pandas.core.sparse.api import SparseDataFrame
9799
return SparseDataFrame
98100
else:
99-
return objs[0]
101+
return next(obj for obj in objs if not type(obj) == SparseDataFrame)
100102

101103

102104
def _concat_compat(to_concat, axis=0):

pandas/tests/sparse/test_combine_concat.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -337,23 +337,24 @@ def test_concat_sparse_dense(self, fill_value):
337337
exp = pd.concat([self.dense3, self.dense1], axis=1)
338338
# See GH18914 and #18686 for why this should be
339339
# A DataFrame
340-
assert isinstance(res, pd.DataFrame)
340+
assert type(res) is pd.DataFrame
341341
# See GH16874
342-
assert res.isnull()
343-
assert res[res.columns[0]]
344-
assert res.iloc[0,0]
342+
assert not res.isnull().empty
343+
assert not res[res.columns[0]].empty
344+
assert res.iloc[0,0] == self.dense3.iloc[0,0]
345+
345346
for column in self.dense3.columns:
346347
tm.assert_series_equal(res[column], exp[column])
347348

348349
tm.assert_frame_equal(res, exp)
349350

350351
res = pd.concat([sparse, self.dense3], axis=1)
351352
exp = pd.concat([self.dense1, self.dense3], axis=1)
352-
assert isinstance(res, pd.DataFrame)
353+
assert type(res) is pd.DataFrame
353354
# See GH16874
354-
assert res.isnull()
355-
assert res[res.columns[0]]
356-
assert res.iloc[0,0]
355+
assert not res.isnull().empty
356+
assert not res[res.columns[0]].empty
357+
assert res.iloc[0,0] == sparse.iloc[0,0]
357358
for column in self.dense3.columns:
358359
tm.assert_series_equal(res[column], exp[column])
359360
tm.assert_frame_equal(res, exp)

0 commit comments

Comments
 (0)