Skip to content

Commit fce521a

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

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-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

+14
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pandas.compat import (is_platform_windows,
99
is_platform_32bit)
1010
from pandas.core.config import option_context
11+
from pandas.core.common import SettingWithCopyWarning
1112

1213

1314
use_32bit_repr = is_platform_windows() or is_platform_32bit()
@@ -116,3 +117,16 @@ def test_sparse_frame(self):
116117

117118
with option_context("display.max_rows", 3):
118119
self.assertEqual(repr(sparse), repr(df))
120+
121+
def test_sparse_repr_after_set(self):
122+
# GH 15488
123+
sdf = pd.SparseDataFrame(index=[0, 1], columns=[0, 1])
124+
125+
# Ignore the warning
126+
old_opt = pd.core.config.get_option('mode.chained_assignment')
127+
pd.core.config.set_option('mode.chained_assignment', None)
128+
sdf[0][0] = 1 # This line triggers the bug
129+
try:
130+
repr(sdf)
131+
finally:
132+
pd.core.config.set_option('mode.chained_assignment', old_opt)

0 commit comments

Comments
 (0)