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

enhancement: add optional row/col paramater to to_latex formatter #13203

Closed
nbecker opened this issue May 17, 2016 · 6 comments · Fixed by #40422
Closed

enhancement: add optional row/col paramater to to_latex formatter #13203

nbecker opened this issue May 17, 2016 · 6 comments · Fixed by #40422
Milestone

Comments

@nbecker
Copy link

nbecker commented May 17, 2016

I need to have to_latex formatter function know the row/col of the item being formatted, so it can modify the formatting of certain items, e.g., set some items in color of bold based on the values in the table.

To do this in a backward compatible way, I propose adding a keyword to to_latex - which would then cause the formatter function to be called as
formatter (element value, row#, col#)

@jorisvandenbossche jorisvandenbossche added the IO LaTeX to_latex label May 17, 2016
@jorisvandenbossche
Copy link
Member

@TomAugspurger How do you envision the new Styler formatting framework can be be used for other things than html? Could we in principle make a LatexStyler that adapts the template and the html specific methods?
In that case that is maybe a better / more powerfull way forward to adapt styling.

@nbecker You know you already have to specify the column for formatters? So the question is only about also knowing the index of the element?

@nbecker
Copy link
Author

nbecker commented May 17, 2016

I want to know the index so I can style certain elements according to some computation. For example,
All elements in column N+1 > corresponding element in column N should be colored green
df['N+1'] > df['N'] -> green
to implement this, I need to formatter to be passed the index

@TomAugspurger
Copy link
Contributor

I think the parts that can be reused are public API parts like Style.format, Styler.render, Styler.apply and Styler.applymap. That gives you iteration logic over every row, and every column in each row, including the style information attached to that item. Also the export / use functionality. Those items could be put in a base class pretty easily I think.

Other than that it'd be up to the subclass to implement

  • the template (I don't think there's much that could be inherited from a base template), which wouldn't be terrible.
  • the _translate method, which would be the bulk of the work
  • Any builtin styles (like .highlight_max)

@TomAugspurger
Copy link
Contributor

I've pushed a branch here sketching out what the start of the refactor might look like.

At this point it's worth asking whether all this is still in scope for pandas? Other than LaTeX I'd say the big one is Markdown, which wouldn't be much code, so maybe it's OK to keep in pandas.

@jnothman
Copy link
Contributor

jnothman commented May 7, 2017

Now that we have Styler.to_excel, I think the option of a similar Styler.to_latex export would be appropriate.

@jnothman
Copy link
Contributor

jnothman commented May 7, 2017

Though note that Styler explicitly sets a style per cell. We won't be producing idiomatic TeX that way, in the sense that we won't control the formatting (justification etc) of entire columns, nor arbitrary macros to reformat a class of cells.

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

Successfully merging a pull request may close this issue.

6 participants