【问题标题】:How to catch Python UDF exceptions when using PyArrow使用 PyArrow 时如何捕获 Python UDF 异常
【发布时间】:2019-12-27 20:37:04
【问题描述】:

启用 PyArrow 后,Executor 引发的 Pandas UDF 异常将无法捕获:请参见下面的示例。这是预期的行为吗?

如果是这样,原因是什么。如果没有,我该如何解决这个问题?

已确认 PyArrow 0.11 和 0.14.1(最新)以及 PySpark 2.4.0 和 2.4.3 中的行为。 Python 3.6.5。

import pandas as pd
from pyspark.sql import SparkSession
from pyspark.sql.functions import udf

spark = SparkSession.builder.getOrCreate()

# setting this to false will allow the exception to be caught
spark.conf.set("spark.sql.execution.arrow.enabled", "true")

@udf
def disrupt(x):
    raise Exception("Test EXCEPTION")

data = spark.createDataFrame(pd.DataFrame({"A": [1, 2, 3]}))

try:
    test = data.withColumn("test", disrupt("A")).toPandas()
except:
    print("exception caught")

print('end')

我希望广泛的 except 能够捕获每一个异常。

【问题讨论】:

    标签: python pyspark user-defined-functions pyarrow


    【解决方案1】:

    更新:据我了解,这是设计使然,但如果有人有任何其他想法,我很乐意听取您的意见。 IE。是否可以让 PyArrow 将异常错误日志指向其他地方?

    【讨论】:

      猜你喜欢
      • 2021-03-18
      • 2018-01-29
      • 1970-01-01
      • 1970-01-01
      • 2021-08-22
      • 2016-07-01
      • 1970-01-01
      • 2010-10-17
      • 2016-12-13
      相关资源
      最近更新 更多