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: _repr_latex is called in jupyter qtconsole #12182

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

Comments

@chris-b1
Copy link
Contributor

@chris-b1 chris-b1 commented Jan 30, 2016

xref #11778

image

@jreback

This comment has been minimized.

Copy link
Contributor

@jreback jreback commented Jan 30, 2016

hmm, is this on master?

@jorisvandenbossche

This comment has been minimized.

Copy link
Member

@jorisvandenbossche jorisvandenbossche commented Jan 30, 2016

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

This comment has been minimized.

Copy link
Member

@jorisvandenbossche jorisvandenbossche commented Jan 30, 2016

I think this is a reason to consider reverting #11778

@jreback

This comment has been minimized.

Copy link
Contributor

@jreback jreback commented Jan 30, 2016

@jorisvandenbossche

This comment has been minimized.

Copy link
Member

@jorisvandenbossche jorisvandenbossche commented Jan 30, 2016

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

This comment has been minimized.

Copy link
Contributor

@jreback jreback commented Jan 30, 2016

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

@chris-b1

This comment has been minimized.

Copy link
Contributor Author

@chris-b1 chris-b1 commented Jan 30, 2016

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

This comment has been minimized.

Copy link
Contributor

@nbonnotte nbonnotte commented Jan 30, 2016

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

This comment has been minimized.

Copy link
Member

@jorisvandenbossche jorisvandenbossche commented Feb 1, 2016

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

This comment has been minimized.

Copy link
Member

@jorisvandenbossche jorisvandenbossche commented Feb 2, 2016

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

This comment has been minimized.

Copy link
Contributor

@nbonnotte nbonnotte commented Feb 2, 2016

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

This comment has been minimized.

Copy link
Member

@jorisvandenbossche jorisvandenbossche commented Feb 2, 2016

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

This comment has been minimized.

Copy link
Contributor

@jreback 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

This comment has been minimized.

Copy link
Member

@jorisvandenbossche jorisvandenbossche commented Feb 9, 2016

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

This comment has been minimized.

Copy link
Contributor Author

@chris-b1 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

This comment has been minimized.

Copy link
Member

@jorisvandenbossche jorisvandenbossche commented Feb 10, 2016

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
@jreback jreback closed this in d207679 Feb 10, 2016
cldy added 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
Projects
None yet
4 participants
You can’t perform that action at this time.