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

to_latex wrong \multicolumn count #17959

Closed
Phibedy opened this Issue Oct 23, 2017 · 5 comments

Comments

Projects
None yet
3 participants
@Phibedy

Phibedy commented Oct 23, 2017

Code Sample

import pandas as pd

pd.DataFrame({"A":[1,2,3]}).to_latex(longtable=True)

Problem description

\begin{longtable}{lr}
\toprule
{} &  A \\
\midrule
\endhead
\midrule
\multicolumn{3}{r}{{Continued on next page}} \\
\midrule
\endfoot

\bottomrule
\endlastfoot
0 &  1 \\
1 &  2 \\
2 &  3 \\
\end{longtable}

It says \multicolumn{3} but it should be 2, it only fails with longtable=True. Indeed it always writes 3 no matter what shape the table has.

Expected Output

\multicolumn{2}

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.5.2.final.0 python-bits: 64 OS: Linux OS-release: 4.10.0-35-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8

pandas: 0.20.1
pytest: None
pip: 9.0.1
setuptools: 20.7.0
Cython: None
numpy: 1.12.1
scipy: 0.19.0
xarray: None
IPython: 6.1.0
sphinx: None
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2013b
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.0.0
openpyxl: None
xlrd: 1.0.0
xlwt: None
xlsxwriter: 0.7.3
lxml: None
bs4: None
html5lib: 0.999999999
sqlalchemy: None
pymysql: None
psycopg2: 2.7.1 (dt dec pq3 ext lo64)
jinja2: 2.8
s3fs: None
pandas_gbq: None
pandas_datareader: None

@gfyoung

This comment has been minimized.

Show comment
Hide comment
@gfyoung

gfyoung Oct 23, 2017

Member

Indeed it always writes 3 no matter what shape the table has.

I'm not sure that should be the case...that being said, feel free to investigate and figure out the cause.

Member

gfyoung commented Oct 23, 2017

Indeed it always writes 3 no matter what shape the table has.

I'm not sure that should be the case...that being said, feel free to investigate and figure out the cause.

@Phibedy

This comment has been minimized.

Show comment
Hide comment
@Phibedy

Phibedy Oct 23, 2017

buf.write('\\multicolumn{3}{r}{{Continued on next '

line 945, the 3 is fixed, it might should be len(rows)

The testcase says also 3 line
368: \multicolumn{3}{r}{{Continued on next page}} \\

\multicolumn{3}{r}{{Continued on next page}} \\

If I change it the test won't work but I dont think that the test is correct.

Phibedy commented Oct 23, 2017

buf.write('\\multicolumn{3}{r}{{Continued on next '

line 945, the 3 is fixed, it might should be len(rows)

The testcase says also 3 line
368: \multicolumn{3}{r}{{Continued on next page}} \\

\multicolumn{3}{r}{{Continued on next page}} \\

If I change it the test won't work but I dont think that the test is correct.

@gfyoung

This comment has been minimized.

Show comment
Hide comment
@gfyoung

gfyoung Oct 23, 2017

Member

Not sure why we are using hard-coded values. Let's change to it (both in the source code and tests) to vary, and let's see how the output looks like when we do that.

(BTW, when I say "see how the output looks", I mean that we should also make sure that it renders properly when converted to PDF for example - that would have to be done somewhat manually)

Member

gfyoung commented Oct 23, 2017

Not sure why we are using hard-coded values. Let's change to it (both in the source code and tests) to vary, and let's see how the output looks like when we do that.

(BTW, when I say "see how the output looks", I mean that we should also make sure that it renders properly when converted to PDF for example - that would have to be done somewhat manually)

syxolk added a commit to syxolk/pandas that referenced this issue Oct 23, 2017

BUG: Fix to_latex with longtable (pandas-dev#17959)
pandas.DataFrame.to_latex(longtable=True) always contained
\multicolumn{3}{r}{{Continued on next page}}
regardless of the number of columns in the output.

@syxolk syxolk referenced this issue Oct 23, 2017

Merged

BUG: Fix to_latex with longtable (#17959) #17960

4 of 4 tasks complete
@jreback

This comment has been minimized.

Show comment
Hide comment
@jreback

jreback Oct 23, 2017

Contributor

is this issue related: #14484

Contributor

jreback commented Oct 23, 2017

is this issue related: #14484

@gfyoung

This comment has been minimized.

Show comment
Hide comment
@gfyoung

gfyoung Oct 23, 2017

Member

@jreback : Not as far as I can tell.

Member

gfyoung commented Oct 23, 2017

@jreback : Not as far as I can tell.

syxolk added a commit to syxolk/pandas that referenced this issue Oct 25, 2017

BUG: Fix to_latex with longtable (pandas-dev#17959)
pandas.DataFrame.to_latex(longtable=True) always contained
\multicolumn{3}{r}{{Continued on next page}}
regardless of the number of columns in the output.

gfyoung added a commit to syxolk/pandas that referenced this issue Dec 8, 2017

BUG: Fix to_latex with longtable (pandas-dev#17959)
pandas.DataFrame.to_latex(longtable=True) always contained
\multicolumn{3}{r}{{Continued on next page}}
regardless of the number of columns in the output.

gfyoung added a commit to syxolk/pandas that referenced this issue Dec 11, 2017

BUG: Fix to_latex with longtable (pandas-dev#17959)
pandas.DataFrame.to_latex(longtable=True) always contained
\multicolumn{3}{r}{{Continued on next page}}
regardless of the number of columns in the output.

@jreback jreback added this to the 0.21.1 milestone Dec 11, 2017

jreback added a commit that referenced this issue Dec 11, 2017

TomAugspurger added a commit to TomAugspurger/pandas that referenced this issue Dec 11, 2017

TomAugspurger added a commit that referenced this issue Dec 12, 2017

yarikoptic added a commit to neurodebian/pandas that referenced this issue Feb 22, 2018

Merge tag 'v0.22.0' into releases
Version 0.22.0

* tag 'v0.22.0': (777 commits)
  RLS: v0.22.0
  DOC: Fix min_count docstring (pandas-dev#19005)
  DOC: More 0.22.0 updates (pandas-dev#19002)
  TST: Remove pow test in expressions
  COMPAT: Avoid td.skip decorator
  DOC: 0.22.0 release docs (pandas-dev#18983)
  DOC: Include 0.22.0 whatsnew
  Breaking changes for sum / prod of empty / all-NA (pandas-dev#18921)
  ENH: Added a min_count keyword to stat funcs (pandas-dev#18876)
  RLS: v0.21.1
  DOC: Add date to whatsnew (pandas-dev#18740)
  DOC: Include 0.21.1 whatsnew
  DOC: Update relase notes (pandas-dev#18739)
  CFG: Ignore W503
  DOC: fix options table (pandas-dev#18730)
  ENH: support non default indexes in writing to Parquet (pandas-dev#18629)
  BUG: Fix to_latex with longtable (pandas-dev#17959) (pandas-dev#17960)
  Parquet: Add error message for no engine found (pandas-dev#18717)
  BUG: Categorical data fails to load from hdf when all columns are NaN (pandas-dev#18652)
  DOC: clean-up whatsnew file for 0.21.1 (pandas-dev#18690)
  ...

yarikoptic added a commit to neurodebian/pandas that referenced this issue Feb 22, 2018

Merge branch 'releases' into debian
* releases: (777 commits)
  RLS: v0.22.0
  DOC: Fix min_count docstring (pandas-dev#19005)
  DOC: More 0.22.0 updates (pandas-dev#19002)
  TST: Remove pow test in expressions
  COMPAT: Avoid td.skip decorator
  DOC: 0.22.0 release docs (pandas-dev#18983)
  DOC: Include 0.22.0 whatsnew
  Breaking changes for sum / prod of empty / all-NA (pandas-dev#18921)
  ENH: Added a min_count keyword to stat funcs (pandas-dev#18876)
  RLS: v0.21.1
  DOC: Add date to whatsnew (pandas-dev#18740)
  DOC: Include 0.21.1 whatsnew
  DOC: Update relase notes (pandas-dev#18739)
  CFG: Ignore W503
  DOC: fix options table (pandas-dev#18730)
  ENH: support non default indexes in writing to Parquet (pandas-dev#18629)
  BUG: Fix to_latex with longtable (pandas-dev#17959) (pandas-dev#17960)
  Parquet: Add error message for no engine found (pandas-dev#18717)
  BUG: Categorical data fails to load from hdf when all columns are NaN (pandas-dev#18652)
  DOC: clean-up whatsnew file for 0.21.1 (pandas-dev#18690)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment