Skip to content

Commit

Permalink
Add more specific tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hexgnu committed Jan 9, 2018
1 parent c69a40e commit bfa713d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
6 changes: 4 additions & 2 deletions pandas/core/dtypes/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,13 @@ def _get_frame_result_type(result, objs):
if all blocks are SparseBlock, return SparseDataFrame
otherwise, return 1st obj
"""

from pandas.core.sparse.api import SparseDataFrame

if result.blocks and all(b.is_sparse for b in result.blocks):
from pandas.core.sparse.api import SparseDataFrame
return SparseDataFrame
else:
return objs[0]
return next(obj for obj in objs if not type(obj) == SparseDataFrame)


def _concat_compat(to_concat, axis=0):
Expand Down
17 changes: 9 additions & 8 deletions pandas/tests/sparse/test_combine_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,23 +337,24 @@ def test_concat_sparse_dense(self, fill_value):
exp = pd.concat([self.dense3, self.dense1], axis=1)
# See GH18914 and #18686 for why this should be
# A DataFrame
assert isinstance(res, pd.DataFrame)
assert type(res) is pd.DataFrame
# See GH16874
assert res.isnull()
assert res[res.columns[0]]
assert res.iloc[0,0]
assert not res.isnull().empty
assert not res[res.columns[0]].empty
assert res.iloc[0,0] == self.dense3.iloc[0,0]

for column in self.dense3.columns:
tm.assert_series_equal(res[column], exp[column])

tm.assert_frame_equal(res, exp)

res = pd.concat([sparse, self.dense3], axis=1)
exp = pd.concat([self.dense1, self.dense3], axis=1)
assert isinstance(res, pd.DataFrame)
assert type(res) is pd.DataFrame
# See GH16874
assert res.isnull()
assert res[res.columns[0]]
assert res.iloc[0,0]
assert not res.isnull().empty
assert not res[res.columns[0]].empty
assert res.iloc[0,0] == sparse.iloc[0,0]
for column in self.dense3.columns:
tm.assert_series_equal(res[column], exp[column])
tm.assert_frame_equal(res, exp)

0 comments on commit bfa713d

Please sign in to comment.