From f0b2c66bf4acb7b12a7b5a21bad157d7f61c557f Mon Sep 17 00:00:00 2001 From: "John H. Ayad" Date: Mon, 22 Mar 2021 23:22:41 +0000 Subject: [PATCH] [SPARK-34803][PYSPARK] Pass the raised ImportError if pandas or pyarrow fail to import (#745) * [SPARK-34803][PYSPARK] Pass the raised ImportError if pandas or pyarrow fail to import * Use six.raise_from * typo * indent * typo --- python/pyspark/sql/pandas/utils.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/python/pyspark/sql/pandas/utils.py b/python/pyspark/sql/pandas/utils.py index 481aa3e6432e1..5190146370e79 100644 --- a/python/pyspark/sql/pandas/utils.py +++ b/python/pyspark/sql/pandas/utils.py @@ -14,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import six def require_minimum_pandas_version(): @@ -26,11 +27,12 @@ def require_minimum_pandas_version(): try: import pandas have_pandas = True - except ImportError: + except ImportError as error: have_pandas = False + raised_error = error if not have_pandas: - raise ImportError("Pandas >= %s must be installed; however, " - "it was not found." % minimum_pandas_version) + six.raise_from(ImportError("Pandas >= %s must be installed; however, " + "it was not found." % minimum_pandas_version), raised_error) if LooseVersion(pandas.__version__) < LooseVersion(minimum_pandas_version): raise ImportError("Pandas >= %s must be installed; however, " "your version was %s." % (minimum_pandas_version, pandas.__version__)) @@ -47,11 +49,12 @@ def require_minimum_pyarrow_version(): try: import pyarrow have_arrow = True - except ImportError: + except ImportError as error: have_arrow = False + raised_error = error if not have_arrow: - raise ImportError("PyArrow >= %s must be installed; however, " - "it was not found." % minimum_pyarrow_version) + six.raise_from(ImportError("PyArrow >= %s must be installed; however, " + "it was not found." % minimum_pyarrow_version), raised_error) if LooseVersion(pyarrow.__version__) < LooseVersion(minimum_pyarrow_version): raise ImportError("PyArrow >= %s must be installed; however, " "your version was %s." % (minimum_pyarrow_version, pyarrow.__version__))