Skip to content

Commit

Permalink
BUG: option to avoid latex in qtconsole pandas-dev#12182
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-b1 committed Feb 10, 2016
1 parent 67730dd commit 8bbf33f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
3 changes: 3 additions & 0 deletions doc/source/options.rst
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
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
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
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
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

0 comments on commit 8bbf33f

Please sign in to comment.