SPRKPY1024
pyspark.sql.functions.log2
Message: pyspark.sql.functions.log2 has a workaround, see documentation for more info
Category: Warning
Description
This issue appears when the SMA detects a use of the pyspark.sql.functions.log2 function, which has a workaround.
Scenario
Input
Below is an example of a use of the pyspark.sql.functions.log2
function that generates this EWI. In this example, the log2
function is used to calculate the base-2 logarithm of the value column.
df = spark.createDataFrame([(1,), (2,), (4,), (8,), (16,)], ["value"])
df_with_log2 = df.withColumn("log2_value", log2(df["value"]))
Output
The SMA adds the EWI SPRKPY1024
to the output code to let you know that this function is not directly supported by Snowpark, but it has a workaround.
df = spark.createDataFrame([(1,), (2,), (4,), (8,), (16,)], ["value"])
#EWI: SPRKPY1024 => pyspark.sql.functions.log2 has a workaround, see documentation for more info
df_with_log2 = df.withColumn("log2_value", log2(df["value"]))
Recommended fix
As a workaround, you can use the snowflake.snowpark.functions.log function by passing the literal value 2
as the base.
df = session.createDataFrame([(1,), (2,), (4,), (8,), (16,)], ["value"])
df_with_log2 = df.withColumn("log2_value", log(2, df["value"]))
Additional recommendations
For more support, you can email us at sma-support@snowflake.com or post an issue in the SMA.
Last updated