Skip to content

Commit 500d36c

Browse files
authored
Make the indirect dependency on jinja2 optional (#203)
1 parent a44c644 commit 500d36c

File tree

9 files changed

+40
-11
lines changed

9 files changed

+40
-11
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ jobs:
5050
- python-version: "3.11"
5151
pandas-version: pre
5252
polars: true
53+
- python-version: "3.11"
54+
uninstall_jinja2: true
5355
runs-on: ubuntu-20.04
5456
steps:
5557
- name: Checkout
@@ -83,6 +85,10 @@ jobs:
8385
if: matrix.polars
8486
run: pip install -e .[polars]
8587

88+
- name: Uninstall jinja2
89+
if: matrix.uninstall_jinja2
90+
run: pip uninstall jinja2 -y
91+
8692
- name: Install a Jupyter Kernel
8793
run: python -m ipykernel install --name itables --user
8894

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Interactive Tables
22

3-
![CI](https://github.com/mwouts/itables/workflows/CI/badge.svg)
3+
![CI](https://github.com/mwouts/itables/actions/workflows/continuous-integration.yml/badge.svg?branch=main)
44
[![codecov.io](https://codecov.io/github/mwouts/itables/coverage.svg?branch=main)](https://codecov.io/github/mwouts/itables?branch=main)
55
[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/mwouts/itables.svg)](https://lgtm.com/projects/g/mwouts/itables/context:python)
66
[![Pypi](https://img.shields.io/pypi/v/itables.svg)](https://pypi.python.org/pypi/itables)

codecov.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
codecov:
22
notify:
3-
after_n_builds: 15
3+
after_n_builds: 10
44

55
comment:
6-
after_n_builds: 15
6+
after_n_builds: 10
77

88
coverage:
99
status:

docs/changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
ITables ChangeLog
22
=================
33

4+
1.6.2 (2023-10-07)
5+
------------------
6+
7+
**Fixed**
8+
- We have removed an indirect dependency on `jinja2` caused by the Pandas style objects ([#202](https://github.com/mwouts/itables/issues/202))
9+
10+
411
1.6.1 (2023-10-01)
512
------------------
613

docs/quick_start.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ kernelspec:
1414

1515
# Quick Start
1616

17-
![CI](https://github.com/mwouts/itables/workflows/CI/badge.svg)
17+
![CI](https://github.com/mwouts/itables/actions/workflows/continuous-integration.yml/badge.svg?branch=main)
1818
[![codecov.io](https://codecov.io/github/mwouts/itables/coverage.svg?branch=main)](https://codecov.io/github/mwouts/itables?branch=main)
1919
[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/mwouts/itables.svg)](https://lgtm.com/projects/g/mwouts/itables/context:python)
2020
[![Pypi](https://img.shields.io/pypi/v/itables.svg)](https://pypi.python.org/pypi/itables)

itables/javascript.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010

1111
import numpy as np
1212
import pandas as pd
13-
import pandas.io.formats.style as pd_style
13+
14+
try:
15+
import pandas.io.formats.style as pd_style
16+
except ImportError:
17+
pd_style = None
1418

1519
try:
1620
import polars as pl
@@ -40,7 +44,9 @@
4044
"warn_on_int_to_str_conversion",
4145
}
4246
_ORIGINAL_DATAFRAME_REPR_HTML = pd.DataFrame._repr_html_
43-
_ORIGINAL_DATAFRAME_STYLE_REPR_HTML = pd_style.Styler._repr_html_
47+
_ORIGINAL_DATAFRAME_STYLE_REPR_HTML = (
48+
None if pd_style is None else pd_style.Styler._repr_html_
49+
)
4450
_ORIGINAL_POLARS_DATAFRAME_REPR_HTML = pl.DataFrame._repr_html_
4551
_CONNECTED = True
4652

@@ -92,12 +98,14 @@ def init_notebook_mode(
9298
if all_interactive:
9399
pd.DataFrame._repr_html_ = _datatables_repr_
94100
pd.Series._repr_html_ = _datatables_repr_
95-
pd_style.Styler._repr_html_ = _datatables_repr_
101+
if pd_style is not None:
102+
pd_style.Styler._repr_html_ = _datatables_repr_
96103
pl.DataFrame._repr_html_ = _datatables_repr_
97104
pl.Series._repr_html_ = _datatables_repr_
98105
else:
99106
pd.DataFrame._repr_html_ = _ORIGINAL_DATAFRAME_REPR_HTML
100-
pd_style.Styler._repr_html_ = _ORIGINAL_DATAFRAME_STYLE_REPR_HTML
107+
if pd_style is not None:
108+
pd_style.Styler._repr_html_ = _ORIGINAL_DATAFRAME_STYLE_REPR_HTML
101109
pl.DataFrame._repr_html_ = _ORIGINAL_POLARS_DATAFRAME_REPR_HTML
102110
if hasattr(pd.Series, "_repr_html_"):
103111
del pd.Series._repr_html_
@@ -267,7 +275,7 @@ def to_html_datatable(
267275
use_to_html=False,
268276
**kwargs
269277
):
270-
if use_to_html or isinstance(df, pd_style.Styler):
278+
if use_to_html or (pd_style is not None and isinstance(df, pd_style.Styler)):
271279
return to_html_datatable_using_to_html(
272280
df=df,
273281
caption=caption,
@@ -445,7 +453,7 @@ def to_html_datatable_using_to_html(
445453
# default UUID in Pandas styler objects has uuid_len=5
446454
or str(uuid.uuid4())[:5]
447455
)
448-
if isinstance(df, pd_style.Styler):
456+
if pd_style is not None and isinstance(df, pd_style.Styler):
449457
if not showIndex:
450458
try:
451459
df = df.hide()

itables/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""ITables' version number"""
22

3-
__version__ = "1.6.1"
3+
__version__ = "1.6.2"

tests/test_documentation_notebooks_run.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66

77
from itables import init_notebook_mode
8+
from itables.javascript import pd_style
89

910
try:
1011
import polars as pl
@@ -27,6 +28,8 @@ def list_doc_notebooks():
2728
def test_run_documentation_notebooks(notebook):
2829
if "polars" in notebook.stem and pl is None:
2930
pytest.skip(msg="Polars is not available")
31+
if "pandas_style" in notebook.stem and pd_style is None:
32+
pytest.skip(msg="Pandas Style is not available")
3033

3134
nb = jupytext.read(notebook)
3235
py_notebook = jupytext.writes(nb, "py:percent")

tests/test_sample_dfs.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from itables import show, to_html_datatable
88
from itables.datatables_format import _format_column, generate_encoder
9+
from itables.javascript import pd_style
910
from itables.sample_dfs import (
1011
COLUMN_TYPES,
1112
PANDAS_VERSION_MAJOR,
@@ -58,6 +59,10 @@ def test_get_indicators(connected, use_to_html):
5859
sys.version_info < (3, 7),
5960
reason="AttributeError: 'Styler' object has no attribute 'to_html'",
6061
)
62+
@pytest.mark.skipif(
63+
pd_style is None,
64+
reason="Missing optional dependency 'Jinja2'. DataFrame.style requires jinja2.",
65+
)
6166
def test_get_pandas_styler(connected, use_to_html):
6267
styler = get_pandas_styler()
6368
show(styler, connected=connected, use_to_html=use_to_html)

0 commit comments

Comments
 (0)