Skip to content

Commit

Permalink
REF: Use Styler implementation for DataFrame.to_latex (#47970)
Browse files Browse the repository at this point in the history
* Base implementation

* Base implementation

* test fix up

* test fix up

* test fix up

* doc change

* doc change

* doc change

* mypy fixes

* ivanov doc comment

* ivanov doc comment

* rhshadrach reduction

* change text  from 1.5.0 to 2.0.0

* remove argument col_space and add whatsnew

* mroeschke requests

* mroeschke requests

* pylint fix

* Whats new text improvements and description added

* Update doc/source/whatsnew/v2.0.0.rst

Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>

* Update doc/source/whatsnew/v2.0.0.rst

* remove trailing whitespace

* remove trailing whitespace

* Whats new linting fixes

* mroeschke requests

Co-authored-by: JHM Darbyshire (iMac) <attack68@users.noreply.github.com>
Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>
  • Loading branch information
3 people committed Jan 19, 2023
1 parent 4d0cc6f commit 5e4ea2e
Show file tree
Hide file tree
Showing 10 changed files with 534 additions and 383 deletions.
33 changes: 33 additions & 0 deletions doc/source/whatsnew/v2.0.0.rst
Expand Up @@ -454,6 +454,37 @@ Now, the axes return an empty :class:`RangeIndex`.
pd.Series().index
pd.DataFrame().axes
.. _whatsnew_200.api_breaking.to_latex:

DataFrame to LaTeX has a new render engine
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The existing :meth:`DataFrame.to_latex` has been restructured to utilise the
extended implementation previously available under :meth:`.Styler.to_latex`.
The arguments signature is similar, albeit ``col_space`` has been removed since
it is ignored by LaTeX engines. This render engine also requires ``jinja2`` as a
dependency which needs to be installed, since rendering is based upon jinja2 templates.

The pandas options below are no longer used and will be removed in future releases.
The alternative options giving similar functionality are indicated below:

- ``display.latex.escape``: replaced with ``styler.format.escape``,
- ``display.latex.longtable``: replaced with ``styler.latex.environment``,
- ``display.latex.multicolumn``, ``display.latex.multicolumn_format`` and
``display.latex.multirow``: replaced with ``styler.sparse.rows``,
``styler.sparse.columns``, ``styler.latex.multirow_align`` and
``styler.latex.multicol_align``,
- ``display.latex.repr``: replaced with ``styler.render.repr``,
- ``display.max_rows`` and ``display.max_columns``: replace with
``styler.render.max_rows``, ``styler.render.max_columns`` and
``styler.render.max_elements``.

Note that the behaviour of ``_repr_latex_`` is also changed. Previously
setting ``display.latex.repr`` would generate LaTeX only when using nbconvert for a
JupyterNotebook, and not when the user is running the notebook. Now the
``styler.render.repr`` option allows control of the specific output
within JupyterNotebooks for operations (not just on nbconvert). See :issue:`39911`.

.. _whatsnew_200.api_breaking.deps:

Increased minimum versions for dependencies
Expand Down Expand Up @@ -619,6 +650,7 @@ Removal of prior version deprecations/changes
- Removed deprecated :meth:`.Styler.set_na_rep` and :meth:`.Styler.set_precision` (:issue:`49397`)
- Removed deprecated :meth:`.Styler.where` (:issue:`49397`)
- Removed deprecated :meth:`.Styler.render` (:issue:`49397`)
- Removed deprecated argument ``col_space`` in :meth:`DataFrame.to_latex` (:issue:`47970`)
- Removed deprecated argument ``null_color`` in :meth:`.Styler.highlight_null` (:issue:`49397`)
- Removed deprecated argument ``check_less_precise`` in :meth:`.testing.assert_frame_equal`, :meth:`.testing.assert_extension_array_equal`, :meth:`.testing.assert_series_equal`, :meth:`.testing.assert_index_equal` (:issue:`30562`)
- Removed deprecated ``null_counts`` argument in :meth:`DataFrame.info`. Use ``show_counts`` instead (:issue:`37999`)
Expand Down Expand Up @@ -793,6 +825,7 @@ Removal of prior version deprecations/changes
- Changed behavior of comparison of ``NaT`` with a ``datetime.date`` object; these now raise on inequality comparisons (:issue:`39196`)
- Enforced deprecation of silently dropping columns that raised a ``TypeError`` in :class:`Series.transform` and :class:`DataFrame.transform` when used with a list or dictionary (:issue:`43740`)
- Changed behavior of :meth:`DataFrame.apply` with list-like so that any partial failure will raise an error (:issue:`43740`)
- Changed behaviour of :meth:`DataFrame.to_latex` to now use the Styler implementation via :meth:`.Styler.to_latex` (:issue:`47970`)
- Changed behavior of :meth:`Series.__setitem__` with an integer key and a :class:`Float64Index` when the key is not present in the index; previously we treated the key as positional (behaving like ``series.iloc[key] = val``), now we treat it is a label (behaving like ``series.loc[key] = val``), consistent with :meth:`Series.__getitem__`` behavior (:issue:`33469`)
- Removed ``na_sentinel`` argument from :func:`factorize`, :meth:`.Index.factorize`, and :meth:`.ExtensionArray.factorize` (:issue:`47157`)
- Changed behavior of :meth:`Series.diff` and :meth:`DataFrame.diff` with :class:`ExtensionDtype` dtypes whose arrays do not implement ``diff``, these now raise ``TypeError`` rather than casting to numpy (:issue:`31025`)
Expand Down

0 comments on commit 5e4ea2e

Please sign in to comment.