Skip to content

BUG-16807-1 SparseFrame fills with default_fill_value if data is None #24842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 3, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.24.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1835,6 +1835,7 @@ Sparse
- Bug in :meth:`SparseArray.nonzero` and :meth:`SparseDataFrame.dropna` returning shifted/incorrect results (:issue:`21172`)
- Bug in :meth:`DataFrame.apply` where dtypes would lose sparseness (:issue:`23744`)
- Bug in :func:`concat` when concatenating a list of :class:`Series` with all-sparse values changing the ``fill_value`` and converting to a dense Series (:issue:`24371`)
- Bug in :class:`SparseFrame` constructor where passing ``None`` as the data would cause ``default_fill_value`` to be ignored (:issue:`16807`)
Copy link
Member

@WillAyd WillAyd Feb 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to 0.24.2


Style
^^^^^
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/sparse/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ def __init__(self, data=None, index=None, columns=None, default_kind=None,
columns = Index([])
else:
for c in columns:
data[c] = SparseArray(np.nan, index=index,
kind=self._default_kind,
data[c] = SparseArray(self._default_fill_value,
index=index, kind=self._default_kind,
fill_value=self._default_fill_value)
mgr = to_manager(data, columns, index)
if dtype is not None:
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/sparse/frame/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,14 @@ def test_notna(self):
'B': [True, False, True, True, False]})
tm.assert_frame_equal(res.to_dense(), exp)

def test_default_fill_value_with_no_data(self):
# GH 16807
expected = pd.SparseDataFrame([[1.0, 1.0], [1.0, 1.0]],
columns=list('ab'), index=range(2))
result = pd.SparseDataFrame(columns=list('ab'), index=range(2),
default_fill_value=1.0)
tm.assert_frame_equal(expected, result)


class TestSparseDataFrameArithmetic(object):

Expand Down