Skip to content

Commit 38a34be

Browse files
kerncjreback
authored andcommitted
BUG: repr SparseDataFrame after setting a value
closes #15488 Author: Kernc <[email protected]> Closes #15489 from kernc/sdf-repr and squashes the following commits: 2dc145c [Kernc] BUG: repr SparseDataFrame after setting a value
1 parent fdee922 commit 38a34be

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
@@ -698,7 +698,7 @@ Bug Fixes
698698

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

703703

704704
- 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
@@ -716,9 +716,6 @@ def to_html(self, classes=None, notebook=False, border=None):
716716
def _get_formatted_column_labels(self, frame):
717717
from pandas.core.index import _sparsify
718718

719-
def is_numeric_dtype(dtype):
720-
return issubclass(dtype.type, np.number)
721-
722719
columns = frame.columns
723720

724721
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)