diff --git a/python/pyspark/sql/utils.py b/python/pyspark/sql/utils.py index 3cacc5b9d021a..fbe0b274b496c 100644 --- a/python/pyspark/sql/utils.py +++ b/python/pyspark/sql/utils.py @@ -118,18 +118,34 @@ def require_test_compiled() -> None: def require_minimum_plotly_version() -> None: """Raise ImportError if plotly is not installed""" + from pyspark.loose_version import LooseVersion + minimum_plotly_version = "4.8" try: - import plotly # noqa: F401 + import plotly + + have_plotly = True except ImportError as error: + have_plotly = False + raised_error = error + if not have_plotly: raise PySparkImportError( errorClass="PACKAGE_NOT_INSTALLED", messageParameters={ - "package_name": "plotly", + "package_name": "Plotly", "minimum_version": str(minimum_plotly_version), }, - ) from error + ) from raised_error + if LooseVersion(plotly.__version__) < LooseVersion(minimum_plotly_version): + raise PySparkImportError( + errorClass="UNSUPPORTED_PACKAGE_VERSION", + messageParameters={ + "package_name": "Plotly", + "minimum_version": str(minimum_plotly_version), + "current_version": str(plotly.__version__), + }, + ) class ForeachBatchFunction: