diff --git a/src/main/scala/com/snowflake/snowpark/functions.scala b/src/main/scala/com/snowflake/snowpark/functions.scala index 2f40dfe4..47eb9cd9 100644 --- a/src/main/scala/com/snowflake/snowpark/functions.scala +++ b/src/main/scala/com/snowflake/snowpark/functions.scala @@ -3354,16 +3354,40 @@ object functions { /** * Computes the natural logarithm of the given value plus one. + *Example + * {{{ + * val df = session.createDataFrame(Seq(0.1)).toDF("a") + * df.select(log1p(col("a"))).show() + * ----------------------- + * |"LOG1P" | + * ----------------------- + * |0.09531017980432493 | + * ----------------------- + * + * }}} + * * @since 1.14.0 - * @param c the value to use + * @param c Column to apply logarithm operation * @return the natural logarithm of the given value plus one. */ def log1p(c: Column): Column = callBuiltin("ln", lit(1) + c) /** * Computes the natural logarithm of the given value plus one. + *Example + * {{{ + * val df = session.createDataFrame(Seq(0.1)).toDF("a") + * df.select(log1p("a").as("log1p")).show() + * ----------------------- + * |"LOG1P" | + * ----------------------- + * |0.09531017980432493 | + * ----------------------- + * + * }}} + * * @since 1.14.0 - * @param columnName the value to use + * @param columnName Column to apply logarithm operation * @return the natural logarithm of the given value plus one. */ def log1p(columnName: String): Column = callBuiltin("ln", lit(1) + col(columnName)) diff --git a/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala b/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala index 18088f36..d150819c 100644 --- a/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala +++ b/src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala @@ -2247,7 +2247,6 @@ trait FunctionSuite extends TestData { test("log10 Column function") { val input = session.createDataFrame(Seq(100)).toDF("a") val expected = Seq(2.0).toDF("log10") - checkAnswer( input.select(log10(col("a")).as("log10")), expected, @@ -2257,7 +2256,6 @@ trait FunctionSuite extends TestData { test("log10 String function") { val input = session.createDataFrame(Seq("100")).toDF("a") val expected = Seq(2.0).toDF("log10") - checkAnswer( input.select(log10("a").as("log10")), expected, @@ -2265,26 +2263,22 @@ trait FunctionSuite extends TestData { } test("log1p Column function") { - val input = session.createDataFrame(Seq(100)).toDF("a") + val input = session.createDataFrame(Seq(0.1)).toDF("a") + val expected = Seq(0.09531017980432493).toDF("log1p") + checkAnswer( + input.select(log1p(col("a")).as("log10")), + expected, + sort = false) + } - input.select(log1p(col("a"))).show() -// val expected = Seq(2.0).toDF("log10") -// -// checkAnswer( -// input.select(log10(col("a")).as("log10")), -// expected, -// sort = false) - } -// -// test("log1p String function") { -// val input = session.createDataFrame(Seq("100")).toDF("a") -// val expected = Seq(2.0).toDF("log10") -// -// checkAnswer( -// input.select(log10("a").as("log10")), -// expected, -// sort = false) -// } + test("log1p String function") { + val input = session.createDataFrame(Seq(0.1)).toDF("a") + val expected = Seq(0.09531017980432493).toDF("log1p") + checkAnswer( + input.select(log1p("a").as("log1p")), + expected, + sort = false) + } }