Skip to content

Commit 2dc145c

Browse files
committed
BUG: repr SparseDataFrame after setting a value
1 parent d80275d commit 2dc145c

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

doc/source/whatsnew/v0.20.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ Bug Fixes
564564

565565
- Bug in ``to_sql`` when writing a DataFrame with numeric index names (:issue:`15404`).
566566
- Bug in ``Series.iloc`` where a ``Categorical`` object for list-like indexes input was returned, where a ``Series`` was expected. (:issue:`14580`)
567-
567+
- Bug in repr-formatting a ``SparseDataFrame`` after a value was set on (a copy of) one of its series (:issue:`15488`)
568568

569569

570570
- Bug in groupby operations with timedelta64 when passing ``numeric_only=False`` (:issue:`5724`)

pandas/formats/format.py

-3
Original file line numberDiff line numberDiff line change
@@ -712,9 +712,6 @@ def to_html(self, classes=None, notebook=False, border=None):
712712
def _get_formatted_column_labels(self, frame):
713713
from pandas.core.index import _sparsify
714714

715-
def is_numeric_dtype(dtype):
716-
return issubclass(dtype.type, np.number)
717-
718715
columns = frame.columns
719716

720717
if isinstance(columns, MultiIndex):

pandas/tests/sparse/test_format.py

+12
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,15 @@ def test_sparse_frame(self):
116116

117117
with option_context("display.max_rows", 3):
118118
self.assertEqual(repr(sparse), repr(df))
119+
120+
def test_sparse_repr_after_set(self):
121+
# GH 15488
122+
sdf = pd.SparseDataFrame([[np.nan, 1], [2, np.nan]])
123+
res = sdf.copy()
124+
125+
# Ignore the warning
126+
with pd.option_context('mode.chained_assignment', None):
127+
sdf[0][1] = 2 # This line triggers the bug
128+
129+
repr(sdf)
130+
tm.assert_sp_frame_equal(sdf, res)

0 commit comments

Comments
 (0)