From c7b7b8af4f868445d4b6b2b9fc125e6b5fb0a02d Mon Sep 17 00:00:00 2001 From: Judah Rand <17158624+judahrand@users.noreply.github.com> Date: Mon, 11 Sep 2023 09:27:39 +0100 Subject: [PATCH 1/4] Add `isnan` and `iszero` --- datafusion/tests/test_functions.py | 4 ++++ src/functions.rs | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/datafusion/tests/test_functions.py b/datafusion/tests/test_functions.py index 1727e7e5b..283a79e34 100644 --- a/datafusion/tests/test_functions.py +++ b/datafusion/tests/test_functions.py @@ -131,6 +131,8 @@ def test_math_functions(): f.sinh(col_v), f.tanh(col_v), f.factorial(literal(6)), + f.isnan(col_nav), + f.iszero(col_nav), ) batches = df.collect() assert len(batches) == 1 @@ -185,6 +187,8 @@ def test_math_functions(): np.testing.assert_array_almost_equal(result.column(32), np.sinh(values)) np.testing.assert_array_almost_equal(result.column(33), np.tanh(values)) np.testing.assert_array_almost_equal(result.column(34), math.factorial(6)) + np.testing.assert_array_almost_equal(result.column(35), np.isnan(na_values)) + np.testing.assert_array_almost_equal(result.column(36), na_values == 0) def test_string_functions(df): diff --git a/src/functions.rs b/src/functions.rs index d9a7d6043..d489ba12a 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -230,7 +230,8 @@ scalar_function!(factorial, Factorial); scalar_function!(floor, Floor); scalar_function!(gcd, Gcd); scalar_function!(initcap, InitCap, "Converts the first letter of each word to upper case and the rest to lower case. Words are sequences of alphanumeric characters separated by non-alphanumeric characters."); -scalar_function!(lcm, Lcm); +scalar_function!(isnan, Isnan); +scalar_function!(iszero, Iszero);scalar_function!(lcm, Lcm); scalar_function!(left, Left, "Returns first n characters in the string, or when n is negative, returns all but last |n| characters."); scalar_function!(ln, Ln); scalar_function!(log, Log); @@ -414,6 +415,8 @@ pub(crate) fn init_module(m: &PyModule) -> PyResult<()> { m.add_wrapped(wrap_pyfunction!(grouping))?; m.add_wrapped(wrap_pyfunction!(in_list))?; m.add_wrapped(wrap_pyfunction!(initcap))?; + m.add_wrapped(wrap_pyfunction!(isnan))?; + m.add_wrapped(wrap_pyfunction!(iszero))?; m.add_wrapped(wrap_pyfunction!(lcm))?; m.add_wrapped(wrap_pyfunction!(left))?; m.add_wrapped(wrap_pyfunction!(length))?; From 426934f6da740d6a5ac1288b13bb4fce771f8cbd Mon Sep 17 00:00:00 2001 From: Judah Rand <17158624+judahrand@users.noreply.github.com> Date: Mon, 11 Sep 2023 09:37:46 +0100 Subject: [PATCH 2/4] Add test for `log` --- datafusion/tests/test_functions.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/datafusion/tests/test_functions.py b/datafusion/tests/test_functions.py index 283a79e34..0cefed608 100644 --- a/datafusion/tests/test_functions.py +++ b/datafusion/tests/test_functions.py @@ -133,6 +133,7 @@ def test_math_functions(): f.factorial(literal(6)), f.isnan(col_nav), f.iszero(col_nav), + f.log(literal(3), col_v + literal(pa.scalar(1))), ) batches = df.collect() assert len(batches) == 1 @@ -189,6 +190,9 @@ def test_math_functions(): np.testing.assert_array_almost_equal(result.column(34), math.factorial(6)) np.testing.assert_array_almost_equal(result.column(35), np.isnan(na_values)) np.testing.assert_array_almost_equal(result.column(36), na_values == 0) + np.testing.assert_array_almost_equal( + result.column(37), np.emath.logn(3, values + 1.0) + ) def test_string_functions(df): From 3bbbe9ce8541d99488de3984332712b5545a0484 Mon Sep 17 00:00:00 2001 From: Judah Rand <17158624+judahrand@users.noreply.github.com> Date: Mon, 11 Sep 2023 19:04:01 +0100 Subject: [PATCH 3/4] Add missing newline! Co-authored-by: Liang-Chi Hsieh --- src/functions.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/functions.rs b/src/functions.rs index d489ba12a..79cc19b3c 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -231,7 +231,8 @@ scalar_function!(floor, Floor); scalar_function!(gcd, Gcd); scalar_function!(initcap, InitCap, "Converts the first letter of each word to upper case and the rest to lower case. Words are sequences of alphanumeric characters separated by non-alphanumeric characters."); scalar_function!(isnan, Isnan); -scalar_function!(iszero, Iszero);scalar_function!(lcm, Lcm); +scalar_function!(iszero, Iszero); +scalar_function!(lcm, Lcm); scalar_function!(left, Left, "Returns first n characters in the string, or when n is negative, returns all but last |n| characters."); scalar_function!(ln, Ln); scalar_function!(log, Log); From 4758a166c5486311318ce111f3cd54498f2d3905 Mon Sep 17 00:00:00 2001 From: Judah Rand <17158624+judahrand@users.noreply.github.com> Date: Mon, 11 Sep 2023 21:30:48 +0100 Subject: [PATCH 4/4] Fix linting --- datafusion/tests/test_functions.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/datafusion/tests/test_functions.py b/datafusion/tests/test_functions.py index 0cefed608..80795bf12 100644 --- a/datafusion/tests/test_functions.py +++ b/datafusion/tests/test_functions.py @@ -188,7 +188,9 @@ def test_math_functions(): np.testing.assert_array_almost_equal(result.column(32), np.sinh(values)) np.testing.assert_array_almost_equal(result.column(33), np.tanh(values)) np.testing.assert_array_almost_equal(result.column(34), math.factorial(6)) - np.testing.assert_array_almost_equal(result.column(35), np.isnan(na_values)) + np.testing.assert_array_almost_equal( + result.column(35), np.isnan(na_values) + ) np.testing.assert_array_almost_equal(result.column(36), na_values == 0) np.testing.assert_array_almost_equal( result.column(37), np.emath.logn(3, values + 1.0)