Skip to content

Commit

Permalink
BUG: SparseDataFrame iff all are sparse
Browse files Browse the repository at this point in the history
  • Loading branch information
hexgnu committed Dec 28, 2017
1 parent 0c5f154 commit cb099dd
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pandas/core/dtypes/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _get_frame_result_type(result, objs):
if any block is SparseBlock, return SparseDataFrame
otherwise, return 1st obj
"""
if any(b.is_sparse for b in result.blocks):
if all(b.is_sparse for b in result.blocks):
from pandas.core.sparse.api import SparseDataFrame
return SparseDataFrame
else:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/sparse/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def to_dense(self):
-------
df : DataFrame
"""
data = {k: v.to_dense() if is_sparse(v) else v for k, v in compat.iteritems(self)}
data = {k: v.to_dense() for k, v in compat.iteritems(self)}
return DataFrame(data, index=self.index, columns=self.columns)

def _apply_columns(self, func):
Expand Down
1 change: 0 additions & 1 deletion pandas/core/sparse/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ def __init__(self, data=None, index=None, sparse_index=None, kind='block',
if index is None:
index = data.index.view()
else:

data = data.reindex(index, copy=False)

else:
Expand Down
11 changes: 1 addition & 10 deletions pandas/tests/sparse/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import pandas as pd
from distutils.version import LooseVersion

from pandas import Series, DataFrame, bdate_range, Panel, get_dummies
from pandas import Series, DataFrame, bdate_range, Panel
from pandas.core.dtypes.common import (
is_bool_dtype,
is_float_dtype,
Expand Down Expand Up @@ -322,15 +322,6 @@ def test_density(self):

assert df.density == 0.75

def test_sparse_to_dense(self):
# See gh-
sdf = DataFrame.from_items([('GDP', [1, 2]),('Nation', ['AB', 'CD'])])
sdf = get_dummies(sdf, columns=['Nation'], sparse=True)
df = sdf.to_dense()

tm.assert_frame_equals(df, sdf)


def test_sparse_series_ops(self):
self._check_frame_ops(self.frame)

Expand Down

0 comments on commit cb099dd

Please sign in to comment.