Skip to content

Commit beabf26

Browse files
judahrandviirya
andauthored
Add isnan and iszero (#495)
* Add `isnan` and `iszero` * Add test for `log` * Add missing newline! Co-authored-by: Liang-Chi Hsieh <[email protected]> * Fix linting --------- Co-authored-by: Liang-Chi Hsieh <[email protected]>
1 parent af4f758 commit beabf26

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

datafusion/tests/test_functions.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ def test_math_functions():
131131
f.sinh(col_v),
132132
f.tanh(col_v),
133133
f.factorial(literal(6)),
134+
f.isnan(col_nav),
135+
f.iszero(col_nav),
136+
f.log(literal(3), col_v + literal(pa.scalar(1))),
134137
)
135138
batches = df.collect()
136139
assert len(batches) == 1
@@ -185,6 +188,13 @@ def test_math_functions():
185188
np.testing.assert_array_almost_equal(result.column(32), np.sinh(values))
186189
np.testing.assert_array_almost_equal(result.column(33), np.tanh(values))
187190
np.testing.assert_array_almost_equal(result.column(34), math.factorial(6))
191+
np.testing.assert_array_almost_equal(
192+
result.column(35), np.isnan(na_values)
193+
)
194+
np.testing.assert_array_almost_equal(result.column(36), na_values == 0)
195+
np.testing.assert_array_almost_equal(
196+
result.column(37), np.emath.logn(3, values + 1.0)
197+
)
188198

189199

190200
def test_string_functions(df):

src/functions.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ scalar_function!(factorial, Factorial);
230230
scalar_function!(floor, Floor);
231231
scalar_function!(gcd, Gcd);
232232
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.");
233+
scalar_function!(isnan, Isnan);
234+
scalar_function!(iszero, Iszero);
233235
scalar_function!(lcm, Lcm);
234236
scalar_function!(left, Left, "Returns first n characters in the string, or when n is negative, returns all but last |n| characters.");
235237
scalar_function!(ln, Ln);
@@ -414,6 +416,8 @@ pub(crate) fn init_module(m: &PyModule) -> PyResult<()> {
414416
m.add_wrapped(wrap_pyfunction!(grouping))?;
415417
m.add_wrapped(wrap_pyfunction!(in_list))?;
416418
m.add_wrapped(wrap_pyfunction!(initcap))?;
419+
m.add_wrapped(wrap_pyfunction!(isnan))?;
420+
m.add_wrapped(wrap_pyfunction!(iszero))?;
417421
m.add_wrapped(wrap_pyfunction!(lcm))?;
418422
m.add_wrapped(wrap_pyfunction!(left))?;
419423
m.add_wrapped(wrap_pyfunction!(length))?;

0 commit comments

Comments
 (0)