Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: fix to_latex() when using MultiIndex with NaN in (#14249) (v2) #20797

Merged
merged 3 commits into from
Apr 25, 2018

Conversation

tomneep
Copy link
Contributor

@tomneep tomneep commented Apr 23, 2018

This is an improved version of #19910 cleaning up MultiIndex handling in the process.

I quickly looked at some other issues that this didn't originally aim to address and found that this PR closes #19981 and #18326 too, but I didn't add a tests or whats new entries for those (yet).

Edit: tests and whatsnew entries added for:

@codecov
Copy link

codecov bot commented Apr 23, 2018

Codecov Report

Merging #20797 into master will decrease coverage by 0.07%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #20797      +/-   ##
==========================================
- Coverage   91.85%   91.77%   -0.08%     
==========================================
  Files         153      153              
  Lines       49310    49257      -53     
==========================================
- Hits        45292    45207      -85     
- Misses       4018     4050      +32
Flag Coverage Δ
#multiple 90.16% <100%> (-0.08%) ⬇️
#single 41.87% <0%> (-0.02%) ⬇️
Impacted Files Coverage Δ
pandas/io/formats/latex.py 100% <100%> (ø) ⬆️
pandas/plotting/_converter.py 63.2% <0%> (-3.61%) ⬇️
pandas/core/nanops.py 95.13% <0%> (-1.17%) ⬇️
pandas/core/resample.py 96.06% <0%> (-0.37%) ⬇️
pandas/core/indexes/base.py 96.63% <0%> (-0.06%) ⬇️
pandas/core/common.py 92.01% <0%> (-0.03%) ⬇️
pandas/core/indexes/datetimelike.py 96.7% <0%> (-0.02%) ⬇️
pandas/core/arrays/base.py 84.14% <0%> (ø) ⬆️
pandas/core/frame.py 97.17% <0%> (ø) ⬆️
pandas/core/series.py 93.9% <0%> (ø) ⬆️
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 31e77b0...2a05733. Read the comment docs.

@toobaz
Copy link
Member

toobaz commented Apr 24, 2018

The patch looks good, and thanks for investigating the related issues. If you could also add tests for them too, it would be great.

@jreback jreback added Bug IO LaTeX to_latex labels Apr 24, 2018
@jreback jreback added this to the 0.23.0 milestone Apr 24, 2018
@jreback
Copy link
Contributor

jreback commented Apr 24, 2018

lgtm. @toobaz merge when satisfied.

@toobaz
Copy link
Member

toobaz commented Apr 24, 2018

@tomneep I just found out this PR fixes #18669 too: the original testcase cannot be reproduced (because of #18882 ), but the following can:

In [2]: mi = pd.MultiIndex.from_product([[1, 2]])

In [3]: df = pd.DataFrame(-1, index=mi, columns=range(4))

In [4]: df.index.names = ['']

In [5]: print(df.to_latex())
\begin{tabular}{lrrrr}
\toprule
  &  0 &  1 &  2 &  3 \\
\midrule
1 &    &    &    &    \\
2 & -1 & -1 & -1 & -1 \\
\bottomrule
\end{tabular}

Would you mind adding a test/whatsnew mention for this? Then I think we're ready to go.

@tomneep
Copy link
Contributor Author

tomneep commented Apr 24, 2018

@toobaz Thanks for spotting that one too. I've added a test and whatsnew entry. The output is slightly different than your expected output in #18669 as there is an extra empty row for the index name (which is empty) but I've checked and this is consistent with what to_string() and to_html() do.

@toobaz toobaz merged commit 7ec74e5 into pandas-dev:master Apr 25, 2018
@toobaz
Copy link
Member

toobaz commented Apr 25, 2018

@tomneep thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants