Skip to content

Commit 5c075c3

Browse files
zhengruifengHyukjinKwon
authored andcommitted
[SPARK-50667][PYTHON][TESTS] Make jinja2 optional in PySpark Tests
### What changes were proposed in this pull request? Make `jinja2` optional in PySpark Tests ### Why are the changes needed? `jinja2` is an optional dependency of `pandas` https://pypi.org/pypi/pandas/2.2.0/json ``` 'jinja2>=3.1.2; extra == "output-formatting"' ``` It is not a mandatory requirement of pyspark, so PySpark tests should succeed even it is not installed ### Does this PR introduce _any_ user-facing change? no, test-only ### How was this patch tested? manually test after uninstalling it ### Was this patch authored or co-authored using generative AI tooling? no Closes apache#49288 from zhengruifeng/optional_jinja2. Authored-by: Ruifeng Zheng <[email protected]> Signed-off-by: Hyukjin Kwon <[email protected]>
1 parent 2475b35 commit 5c075c3

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

python/pyspark/pandas/frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2632,7 +2632,7 @@ def to_latex(
26322632
... 'mask': ['red', 'purple'],
26332633
... 'weapon': ['sai', 'bo staff']},
26342634
... columns=['name', 'mask', 'weapon'])
2635-
>>> print(df.to_latex(index=False)) # doctest: +NORMALIZE_WHITESPACE
2635+
>>> print(df.to_latex(index=False)) # doctest: +SKIP
26362636
\begin{tabular}{lll}
26372637
\toprule
26382638
name & mask & weapon \\

python/pyspark/pandas/tests/io/test_dataframe_conversion.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from pyspark import pandas as ps
2727
from pyspark.testing.pandasutils import PandasOnSparkTestCase, TestUtils
2828
from pyspark.testing.sqlutils import SQLTestUtils
29+
from pyspark.testing.utils import have_jinja2, jinja2_requirement_message
2930

3031

3132
class DataFrameConversionMixin:
@@ -199,6 +200,7 @@ def test_to_clipboard(self):
199200
psdf.to_clipboard(sep=";", index=False), pdf.to_clipboard(sep=";", index=False)
200201
)
201202

203+
@unittest.skipIf(not have_jinja2, jinja2_requirement_message)
202204
def test_to_latex(self):
203205
pdf = self.pdf
204206
psdf = self.psdf

python/pyspark/testing/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ def have_package(name: str) -> bool:
9494
have_flameprof = have_package("flameprof")
9595
flameprof_requirement_message = None if have_flameprof else "No module named 'flameprof'"
9696

97+
have_jinja2 = have_package("jinja2")
98+
jinja2_requirement_message = None if have_jinja2 else "No module named 'jinja2'"
99+
97100
pandas_requirement_message = None
98101
try:
99102
from pyspark.sql.pandas.utils import require_minimum_pandas_version

0 commit comments

Comments
 (0)