From bfd7ef6c7652698cd20a47fd7367529a3daa8367 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Sat, 4 Sep 2021 14:45:32 +0200 Subject: [PATCH 1/3] longtable label allowed even when caption is None --- pandas/io/formats/templates/latex_longtable.tpl | 5 +++++ pandas/tests/io/formats/style/test_to_latex.py | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pandas/io/formats/templates/latex_longtable.tpl b/pandas/io/formats/templates/latex_longtable.tpl index fdb45aea83c16..34da6fd0db55e 100644 --- a/pandas/io/formats/templates/latex_longtable.tpl +++ b/pandas/io/formats/templates/latex_longtable.tpl @@ -23,6 +23,11 @@ {%- if label is not none %} \label{{label}} {%- endif %} \\ +{% else %} +{%- set label = parse_table(table_styles, 'label') %} +{%- if label is not none %} + \label{{label}} \\ +{%- endif %} {% endif %} {% set toprule = parse_table(table_styles, 'toprule') %} {% if toprule is not none %} diff --git a/pandas/tests/io/formats/style/test_to_latex.py b/pandas/tests/io/formats/style/test_to_latex.py index 671219872bb34..42ae06e151562 100644 --- a/pandas/tests/io/formats/style/test_to_latex.py +++ b/pandas/tests/io/formats/style/test_to_latex.py @@ -109,10 +109,11 @@ def test_position(styler): assert "\\end{table}" in styler.to_latex() -def test_label(styler): - assert "\\label{text}" in styler.to_latex(label="text") +@pytest.mark.parametrize("env", [None, "longtable"]) +def test_label(styler, env): + assert "\\label{text}" in styler.to_latex(label="text", environment=env) styler.set_table_styles([{"selector": "label", "props": ":{more §text}"}]) - assert "\\label{more :text}" in styler.to_latex() + assert "\\label{more :text}" in styler.to_latex(environment=env) def test_position_float_raises(styler): From 28950e76d6bb4cdfcdd0494727063e8a2b78656d Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Sat, 4 Sep 2021 14:50:45 +0200 Subject: [PATCH 2/3] longtable label allowed even when caption is None --- pandas/io/formats/templates/latex_longtable.tpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/io/formats/templates/latex_longtable.tpl b/pandas/io/formats/templates/latex_longtable.tpl index 34da6fd0db55e..4545723785805 100644 --- a/pandas/io/formats/templates/latex_longtable.tpl +++ b/pandas/io/formats/templates/latex_longtable.tpl @@ -26,8 +26,8 @@ {% else %} {%- set label = parse_table(table_styles, 'label') %} {%- if label is not none %} - \label{{label}} \\ -{%- endif %} +\label{{label}} \\ +{% endif %} {% endif %} {% set toprule = parse_table(table_styles, 'toprule') %} {% if toprule is not none %} From 61533d72dd0be45892978bee3fab483ad21b0707 Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (iMac)" Date: Sat, 4 Sep 2021 14:54:39 +0200 Subject: [PATCH 3/3] longtable label allowed even when caption is None --- pandas/tests/io/formats/style/test_to_latex.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/io/formats/style/test_to_latex.py b/pandas/tests/io/formats/style/test_to_latex.py index 42ae06e151562..a9623f2815c7e 100644 --- a/pandas/tests/io/formats/style/test_to_latex.py +++ b/pandas/tests/io/formats/style/test_to_latex.py @@ -111,9 +111,9 @@ def test_position(styler): @pytest.mark.parametrize("env", [None, "longtable"]) def test_label(styler, env): - assert "\\label{text}" in styler.to_latex(label="text", environment=env) + assert "\n\\label{text}" in styler.to_latex(label="text", environment=env) styler.set_table_styles([{"selector": "label", "props": ":{more §text}"}]) - assert "\\label{more :text}" in styler.to_latex(environment=env) + assert "\n\\label{more :text}" in styler.to_latex(environment=env) def test_position_float_raises(styler):