Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fixed append to extend bug, added test and note.
  • Loading branch information
agartland committed May 31, 2017
commit 06238ee1e9a53a27f9986a485a764c71aca8f1a5
3 changes: 2 additions & 1 deletion doc/source/whatsnew/v0.20.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ Bug Fixes
- Bug in ``DataFrame.update()`` with ``overwrite=False`` and ``NaN values`` (:issue:`15593`)
- Passing an invalid engine to :func:`read_csv` now raises an informative
``ValueError`` rather than ``UnboundLocalError``. (:issue:`16511`)

- Fixed `DataFrame.to_latex(sparsify=True)`. Latex conversion of a `MultiIndex` was
"blanking" repeated values inapproriately. Output now matches string output.



Expand Down
4 changes: 2 additions & 2 deletions pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,9 +891,9 @@ def get_col_type(dtype):
lev3 = [blank] * clevels
if name:
lev3.append(lev.name)
lev3.append(fmt_lev3[i])

lev3.extend(fmt_lev3[i])
strcols.insert(i, lev3)

column_format = self.column_format
if column_format is None:
dtypes = self.frame.dtypes._values
Expand Down
27 changes: 27 additions & 0 deletions pandas/tests/io/formats/test_to_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,3 +506,30 @@ def test_to_latex_series(self):
\end{tabular}
"""
assert withindex_result == withindex_expected

def test_to_latex_sparsify(self, frame):
# GH 12031
frame.to_latex()

df = DataFrame({'a':[1,2,1,2,3,2,1,1,1,3,2,4,2,1],
'b':[1,2,1,2,2,2,1,1,2,1,2,1,2,1],
'c':[5,6,5,5,5,5,5,6,5,5,5,6,5,6]})
df = df.groupby(['a', 'b']).agg(sum)
withindex_result = df.to_latex(sparsify=True)

withindex_expected = r"""\begin{tabular}{llr}
\toprule
& & c \\
a & b & \\
\midrule
1 & 1 & 27 \\
{} & 2 & 5 \\
2 & 2 & 26 \\
3 & 1 & 5 \\
{} & 2 & 5 \\
4 & 1 & 6 \\
\bottomrule
\end{tabular}
"""

assert withindex_result == withindex_expected