Skip to content

BUG: LatexFormatter.write_result multi-index #17499

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

Conversation

MaximilianKoestler
Copy link

@MaximilianKoestler MaximilianKoestler commented Sep 12, 2017

Fixed GH issue 14484:

LatexFormatter.write_result(...) now does not print blanks if a
higher-order index differs from the previous row.
Also added testcase for this.

@codecov
Copy link

codecov bot commented Sep 12, 2017

Codecov Report

Merging #17499 into master will decrease coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #17499      +/-   ##
==========================================
- Coverage   91.18%   91.17%   -0.02%     
==========================================
  Files         163      163              
  Lines       49543    49547       +4     
==========================================
- Hits        45177    45172       -5     
- Misses       4366     4375       +9
Flag Coverage Δ
#multiple 88.95% <100%> (ø) ⬆️
#single 40.21% <0%> (-0.07%) ⬇️
Impacted Files Coverage Δ
pandas/io/formats/format.py 96.06% <100%> (+0.01%) ⬆️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/frame.py 97.77% <0%> (-0.1%) ⬇️

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 f11bbf2...6eadb87. Read the comment docs.

@@ -415,6 +415,7 @@ I/O
- Bug in :func:`read_stata` where value labels could not be read when using an iterator (:issue:`16923`)
- Bug in :func:`read_html` where import check fails when run in multiple threads (:issue:`16928`)
- Bug in :func:`read_csv` where automatic delimiter detection caused a ``TypeError`` to be thrown when a bad line was encountered rather than the correct error message (:issue:`13374`)
- Bug in ``LatexFormatter.write_result`` where repeated multi-index values were not printed even though a higher level index differed from the previous row (:issue:`14484`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reference the function that users will care about, which is "to_latex" instead of "LatexFormatter.write_result" . Also, follow the convention used in the two lines above when referencing "to_latex" with the func notation.

@@ -221,6 +221,22 @@ def test_to_latex_multiindex(self):

assert result == expected

# GH 14484
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add more comments about what you're testing here.

@MaximilianKoestler
Copy link
Author

MaximilianKoestler commented Sep 13, 2017

@gfyoung Thanks for the comments, it is fixed and green again

@@ -415,6 +415,7 @@ I/O
- Bug in :func:`read_stata` where value labels could not be read when using an iterator (:issue:`16923`)
- Bug in :func:`read_html` where import check fails when run in multiple threads (:issue:`16928`)
- Bug in :func:`read_csv` where automatic delimiter detection caused a ``TypeError`` to be thrown when a bad line was encountered rather than the correct error message (:issue:`13374`)
- Bug in :func:`to_latex` where repeated multi-index values were not printed even though a higher level index differed from the previous row (:issue:`14484`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might have to simplify this, but I'll see what @jreback thinks.

Copy link
Member

@gfyoung gfyoung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides my comment about the whatsnew (wait until @jreback comments), this looks good to go.

@@ -897,11 +897,19 @@ def get_col_type(dtype):
lev3 = [blank] * clevels
if name:
lev3.append(lev.name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be better to restructure this whole loop.

iterating like this:

for g, grp in table.groupby(level=0):
      # grp is a DataFrame

would be simpler to print out I think.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct, using df.groupby makes it simpler. Change is implemented and I will ping you once it is green.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just had to revert my change. My attempt using df.groupby() changed the order of some elements and it didn't format more complex indicies like dates correctly.

The current approach does not have any of these issues, so I think it is the best I can do right now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, neither of these should be true, come back when you can

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jreback The change in the order of some elements is caused by a bug in df.groupby() that I just reported. #17537

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok thanks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MXKY Hi, I've fixed your issue #17537.
Nothing stands in your way!

@MaximilianKoestler MaximilianKoestler force-pushed the latex_formatter_patch branch 3 times, most recently from e21d2f3 to 1291ead Compare September 13, 2017 13:30
Fixed GH issue 14484:
`LatexFormatter.write_result`` now does not print blanks if a
higher-order index differs from the previous row.
Also added testcase for this.
@@ -415,6 +415,7 @@ I/O
- Bug in :func:`read_stata` where value labels could not be read when using an iterator (:issue:`16923`)
- Bug in :func:`read_html` where import check fails when run in multiple threads (:issue:`16928`)
- Bug in :func:`read_csv` where automatic delimiter detection caused a ``TypeError`` to be thrown when a bad line was encountered rather than the correct error message (:issue:`13374`)
- Bug in :func:`to_latex` where repeated multi-index values were not printed even though a higher level index differed from the previous row (:issue:`14484`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you move to 0.21.1

@@ -221,6 +221,28 @@ def test_to_latex_multiindex(self):

assert result == expected

# GH 14484
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make this a separate test

@jreback
Copy link
Contributor

jreback commented Dec 8, 2017

can you update

@gfyoung gfyoung self-assigned this Dec 8, 2017
@gfyoung
Copy link
Member

gfyoung commented Dec 8, 2017

@jreback : I can carry this one to the finish line.

@jreback
Copy link
Contributor

jreback commented Dec 8, 2017

great!

feel free to pick up any PR that is not responsive from the author and can be finished

gfyoung added a commit to forking-repos/pandas that referenced this pull request Dec 8, 2017
@gfyoung gfyoung added this to the No action milestone Dec 8, 2017
@gfyoung
Copy link
Member

gfyoung commented Dec 8, 2017

@jreback : Could not push to the remote (permissions), so I opened #18685 .

@gfyoung gfyoung removed their assignment Dec 8, 2017
@jreback jreback closed this Dec 8, 2017
jreback pushed a commit that referenced this pull request Dec 8, 2017
* BUG: LatexFormatter.write_result multi-index

Fixed GH issue 14484:
`LatexFormatter.write_result`` now does not print blanks if a
higher-order index differs from the previous row.
Also added testcase for this.

* MAINT: Address reviewer comments

Closes gh-14484
Closes gh-17499
TomAugspurger pushed a commit to TomAugspurger/pandas that referenced this pull request Dec 8, 2017
* BUG: LatexFormatter.write_result multi-index

Fixed GH issue 14484:
`LatexFormatter.write_result`` now does not print blanks if a
higher-order index differs from the previous row.
Also added testcase for this.

* MAINT: Address reviewer comments

Closes pandas-devgh-14484
Closes pandas-devgh-17499
TomAugspurger pushed a commit that referenced this pull request Dec 11, 2017
* BUG: LatexFormatter.write_result multi-index

Fixed GH issue 14484:
`LatexFormatter.write_result`` now does not print blanks if a
higher-order index differs from the previous row.
Also added testcase for this.

* MAINT: Address reviewer comments

Closes gh-14484
Closes gh-17499
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: to_latex outputs string with missing second index level values
4 participants