Skip to content

Commit

Permalink
[SPARK-34803][PYSPARK] Pass the raised ImportError if pandas or pyarr…
Browse files Browse the repository at this point in the history
…ow 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
  • Loading branch information
johnhany97 authored Mar 22, 2021
1 parent 786fce2 commit f0b2c66
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions python/pyspark/sql/pandas/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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__))
Expand All @@ -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__))
Expand Down

0 comments on commit f0b2c66

Please sign in to comment.