无法在udf函数内使用numpy

时间:2020-02-18 05:39:26

标签: python numpy kubernetes pyspark

我正在尝试在Spark kubernetes集群上运行一些代码

"spark.kubernetes.container.image", "kublr/spark-py:2.4.0-hadoop-2.6"

我要运行的代码如下

def getMax(row, subtract):
    '''
    getMax takes two parameters - 
    row: array with parameters
    subtract: normal value of the parameter
    It outputs the value most distant from the normal
    '''
    try:
        row = np.array(row)
        out = row[np.argmax(row-subtract)]
    except ValueError:
        return None
    return out.item()

from pyspark.sql.types import FloatType
udf_getMax = F.udf(getMax, FloatType())

我要传递的数据帧如下

enter image description here

但是我遇到以下错误

ModuleNotFoundError: No module named 'numpy'

当我执行stackoverflow搜索时,我会在纱线中发现类似的numpy导入错误问题。

ImportError: No module named numpy on spark workers

疯狂的是,我能够将numpy导入到外部,并且

import numpy as np 
函数外的

命令未出现任何错误。

为什么会这样?如何解决此问题或如何前进。任何帮助表示赞赏。

谢谢

0 个答案:

没有答案