Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isnan and iszero #495

Merged
merged 4 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions datafusion/tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ def test_math_functions():
f.sinh(col_v),
f.tanh(col_v),
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
Expand Down Expand Up @@ -185,6 +188,13 @@ 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)
np.testing.assert_array_almost_equal(
result.column(37), np.emath.logn(3, values + 1.0)
)


def test_string_functions(df):
Expand Down
4 changes: 4 additions & 0 deletions src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +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!(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);
Expand Down Expand Up @@ -414,6 +416,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))?;
Expand Down
Loading