Skip to content

Commit

Permalink
add scala log function and test case
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-gmahadevan committed Aug 14, 2024
1 parent eb1b2ce commit ca0ad9d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 23 deletions.
28 changes: 26 additions & 2 deletions src/main/scala/com/snowflake/snowpark/functions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
36 changes: 15 additions & 21 deletions src/test/scala/com/snowflake/snowpark_test/FunctionSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -2257,34 +2256,29 @@ 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,
sort = false)
}

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)
}

}

Expand Down

0 comments on commit ca0ad9d

Please sign in to comment.