Skip to content

BUG: _repr_latex is called in jupyter qtconsole #12182

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

Closed
chris-b1 opened this issue Jan 30, 2016 · 16 comments
Closed

BUG: _repr_latex is called in jupyter qtconsole #12182

chris-b1 opened this issue Jan 30, 2016 · 16 comments
Labels
Blocker Blocking issue or pull request for an upcoming release IO LaTeX to_latex Output-Formatting __repr__ of pandas objects, to_string
Milestone

Comments

@chris-b1
Copy link
Contributor

xref #11778

image

@jreback
Copy link
Contributor

jreback commented Jan 30, 2016

hmm, is this on master?

@jreback jreback added Output-Formatting __repr__ of pandas objects, to_string IO LaTeX to_latex labels Jan 30, 2016
@jorisvandenbossche
Copy link
Member

There are some issues at IPython/Jupyter for this: jupyter/qtconsole#65, jupyter/qtconsole#56 (IRkernel has the same problem for the display of their dataframes)

@chris-b1 Would you be able to test if this is solved in qtconsole master?

@jorisvandenbossche jorisvandenbossche added this to the 0.18.0 milestone Jan 30, 2016
@jorisvandenbossche
Copy link
Member

I think this is a reason to consider reverting #11778

@jreback
Copy link
Contributor

jreback commented Jan 30, 2016

cc @nbonnotte

@jorisvandenbossche
Copy link
Member

Or, another option is making the use of the _repr_latex_ optional, and defaulting to False. So somebody who wants this feature for nbconvert, can switch it on, but knowing that it will bug in qtconsole.

@jreback
Copy link
Contributor

jreback commented Jan 30, 2016

so we could have an option display.latex.repr=False maybe?

@chris-b1
Copy link
Contributor Author

Yeah, this also happens on qtconsole master. If there was a way to make this in_qtconsole check work again, that'd be a way to avoid an option.

But since they've restructured all the ipython/jupyter stuff, I don't know how (if it's possible) to do that.

@nbonnotte
Copy link
Contributor

This goes beyond my current use of pandas or jupyter, so I'm not really qualified to say anything.

That being said, I like the idea of being able to nicely export my notebooks containing dataframes to LaTeX. And, if I understand correctly, this is more a bug of the jupyter qtconsole rather than pandas, right? So, if anything, my current understanding of the situation does not convince me that reverting #11778 is absolutely necessary. But maybe it's just because I use jupyter notebooks, and I feel closer to exporting them to LaTeX rather than using the qtconsole.

@jorisvandenbossche
Copy link
Member

And, if I understand correctly, this is more a bug of the jupyter qtconsole rather than pandas, right? So, if anything, my current understanding of the situation does not convince me that reverting #11778 is absolutely necessary. But maybe it's just because I use jupyter notebooks

The qtconsole is used in eg Spyder, which I suppose quite some pandas users will use.
To be clear, ideally we find another solution or workaround so reverting #11778 is not needed. But if not, we cannot ship pandas like this in any case, as it would break the interactive usage for lots of users.

@jorisvandenbossche jorisvandenbossche added the Blocker Blocking issue or pull request for an upcoming release label Feb 1, 2016
@jorisvandenbossche
Copy link
Member

A possible idea is to do something similar as what sympy does, so that the user has to call a function to activate the latex repr support (sympy.init_printing()).
E.g. a pd.options.display.init_latex_repr() (although this being a function is not really consistent with the other options). Calling the function would then add the _repr_latex_ method to DataFrame on the fly.

@nbonnotte
Copy link
Contributor

Would it still be possible to convert a notebook to LaTeX?

And a naive question: what prevents in_qtconsole from working? Is it because jupyter does not want us to know to which front-end it is connected?

@jorisvandenbossche
Copy link
Member

Would it still be possible to convert a notebook to LaTeX?

Yes, but you will just have call this function in the beginning of your notebook that you want to convert to latex to activate the latex repr

And a naive question: what prevents in_qtconsole from working? Is it because jupyter does not want us to know to which front-end it is connected?

As far as I understand, yes, the kernel does not know in which frontend it is run (notebook or qtconsole or ... are all ipykernel.zmqshell.ZMQInteractiveShell ). And if you want to convert a notebook to nbconvert, the latex repr should already be stored inside of the notebook.

@jreback
Copy link
Contributor

jreback commented Feb 9, 2016

@jorisvandenbossche so what should we do about this, revert the actual _repr_latex_ method?

The other changes are fine.

@jorisvandenbossche
Copy link
Member

I think the best would be something like the following:

Have a new pd.options.display.latex_repr option, which defaults to False, and when setting it to True, this triggers a callback function that adds the _latex_repr_ method dynamically to DataFrame.

@chris-b1
Copy link
Contributor Author

chris-b1 commented Feb 9, 2016

It doesn't even need to be a callback, _repr_latex can just return None (if the option is False) and the qtconsole will fallback. I'll submit a PR here shortly.

@jorisvandenbossche
Copy link
Member

Ah, yes, that seems also to work. Even simpler!

chris-b1 added a commit to chris-b1/pandas that referenced this issue Feb 10, 2016
cldy pushed a commit to cldy/pandas that referenced this issue Feb 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocker Blocking issue or pull request for an upcoming release IO LaTeX to_latex Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants