Skip to content

BUG: repr SparseDataFrame after setting a value #15489

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.20.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ Bug Fixes

- Bug in ``to_sql`` when writing a DataFrame with numeric index names (:issue:`15404`).
- Bug in ``Series.iloc`` where a ``Categorical`` object for list-like indexes input was returned, where a ``Series`` was expected. (:issue:`14580`)

- Bug in repr-formatting a ``SparseDataFrame`` after a value was set on (a copy of) one of its series (:issue:`15488`)


- Bug in groupby operations with timedelta64 when passing ``numeric_only=False`` (:issue:`5724`)
Expand Down
3 changes: 0 additions & 3 deletions pandas/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,9 +712,6 @@ def to_html(self, classes=None, notebook=False, border=None):
def _get_formatted_column_labels(self, frame):
from pandas.core.index import _sparsify

def is_numeric_dtype(dtype):
return issubclass(dtype.type, np.number)

columns = frame.columns

if isinstance(columns, MultiIndex):
Expand Down
12 changes: 12 additions & 0 deletions pandas/tests/sparse/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,15 @@ def test_sparse_frame(self):

with option_context("display.max_rows", 3):
self.assertEqual(repr(sparse), repr(df))

def test_sparse_repr_after_set(self):
# GH 15488
sdf = pd.SparseDataFrame([[np.nan, 1], [2, np.nan]])
res = sdf.copy()

# Ignore the warning
with pd.option_context('mode.chained_assignment', None):
sdf[0][1] = 2 # This line triggers the bug

repr(sdf)
tm.assert_sp_frame_equal(sdf, res)