Skip to content

Commit 23e5f38

Browse files
committed
BUG: repr SparseDataFrame after setting a value
1 parent b94186d commit 23e5f38

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

doc/source/whatsnew/v0.20.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ Bug Fixes
562562

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

567567

568568
- 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

+13
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,16 @@ 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(index=[0, 1], columns=[0, 1])
123+
124+
# Ignore the warning
125+
old_opt = pd.core.config.get_option('mode.chained_assignment')
126+
pd.core.config.set_option('mode.chained_assignment', None)
127+
sdf[0][0] = 1 # This line triggers the bug
128+
try:
129+
repr(sdf)
130+
finally:
131+
pd.core.config.set_option('mode.chained_assignment', old_opt)

0 commit comments

Comments
 (0)