Skip to content
Advertisement

Tag: user-defined-functions

PySpark udf returns null when function works in Pandas dataframe

I’m trying to create a user-defined function that takes a cumulative sum of an array and compares the value to another column. Here is a reproducible example: In Pandas, this is the output: In Spark using temp_sdf.withColumn(‘len’, test_function_udf(‘x_ary’, ‘y’)), all of len ends up being null. Would anyone know why this is the case? Also, replacing cumsum_array = np.cumsum(np.flip(x_ary)) fails

Advertisement