Skip to content

BUG: option to avoid latex in qtconsole #12182 #12275

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
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/source/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ display.large_repr truncate For DataFrames exceeding max_rows/max_co
or switch to the view from df.info()
(the behaviour in earlier versions of pandas).
allowable settings, ['truncate', 'info']
display.latex.repr False Whether to produce a latex DataFrame
representation for jupyter frontends
that support it.
display.latex.escape True Escapes special caracters in Dataframes, when
using the to_latex method.
display.latex.longtable False Specifies if the to_latex method of a Dataframe
Expand Down
18 changes: 17 additions & 1 deletion doc/source/whatsnew/v0.18.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,23 @@ New Behavior:
s.index
print(s.to_csv(path=None))

Latex Represenation
^^^^^^^^^^^^^^^^^^^

``DataFrame`` has gained a ``_repr_latex_`` method in order to allow
for conversion to latex in a ipython/jupyter notebook using
nbconvert. (:issue:`11778`)

Note that this must be activated by setting the option ``display.latex.repr``
to ``True`` (issue:`12182`)

For example, if you have a jupyter notebook you plan to convert to latex using
nbconvert, place the statement ``pd.set_option('display.latex.repr', True)``
in the first cell to have the contained DataFrame output also stored as latex.

Options ``display.latex.escape`` and ``display.latex.longtable`` have also been
added to the configuration and are used automatically by the ``to_latex``
method. See the :ref:`options documentation<options>` for more info.

.. _whatsnew_0180.enhancements.other:

Expand All @@ -324,7 +341,6 @@ Other enhancements
- add support for ``AWS_S3_HOST`` env variable when reading from s3 (:issue:`12198`)
- A simple version of ``Panel.round()`` is now implemented (:issue:`11763`)
- For Python 3.x, ``round(DataFrame)``, ``round(Series)``, ``round(Panel)`` will work (:issue:`11763`)
- ``DataFrame`` has gained a ``_repr_latex_`` method in order to allow for automatic conversion to latex in a ipython/jupyter notebook using nbconvert. Options ``display.latex.escape`` and ``display.latex.longtable`` have been added to the configuration and are used automatically by the ``to_latex`` method. (:issue:`11778`)
- ``sys.getsizeof(obj)`` returns the memory usage of a pandas object, including the
values it contains (:issue:`11597`)
- ``Series`` gained an ``is_unique`` attribute (:issue:`11946`)
Expand Down
9 changes: 9 additions & 0 deletions pandas/core/config_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@
(default: False)
"""

pc_latex_repr_doc = """
: boolean
Whether to produce a latex DataFrame representation for jupyter
environments that support it.
(default: False)
"""

pc_line_width_deprecation_warning = """\
line_width has been deprecated, use display.width instead (currently both are
identical)
Expand Down Expand Up @@ -314,6 +321,8 @@ def mpl_style_cb(key):
pc_east_asian_width_doc, validator=is_bool)
cf.register_option('unicode.ambiguous_as_wide', False,
pc_east_asian_width_doc, validator=is_bool)
cf.register_option('latex.repr', False,
pc_latex_repr_doc, validator=is_bool)
cf.register_option('latex.escape', True, pc_latex_escape,
validator=is_bool)
cf.register_option('latex.longtable', False, pc_latex_longtable,
Expand Down
5 changes: 4 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,10 @@ def _repr_latex_(self):
Returns a LaTeX representation for a particular Dataframe.
Mainly for use with nbconvert (jupyter notebook conversion to pdf).
"""
return self.to_latex()
if get_option('display.latex.repr'):
return self.to_latex()
else:
return None

@property
def style(self):
Expand Down
6 changes: 5 additions & 1 deletion pandas/tests/frame/test_repr_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,14 @@ def test_latex_repr(self):
\bottomrule
\end{tabular}
"""
with option_context("display.latex.escape", False):
with option_context("display.latex.escape", False,
'display.latex.repr', True):
df = DataFrame([[r'$\alpha$', 'b', 'c'], [1, 2, 3]])
self.assertEqual(result, df._repr_latex_())

# GH 12182
self.assertIsNone(df._repr_latex_())

def test_info(self):
io = StringIO()
self.frame.info(buf=io)
Expand Down