Skip to content

Commit fee1f73

Browse files
kosiewtimsaucer
authored andcommitted
Add empty scalar function (alias of array_empty), fix a small typo (apache#938)
* feat: add `empty` function as alias of array_empty * fix: correct typo in null_treatment parameter documentation
1 parent 1edb536 commit fee1f73

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

docs/source/user-guide/common-operations/expressions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ approaches.
8282
Indexing an element of an array via ``[]`` starts at index 0 whereas
8383
:py:func:`~datafusion.functions.array_element` starts at index 1.
8484

85-
To check if an array is empty, you can use the function :py:func:`datafusion.functions.array_empty`.
85+
To check if an array is empty, you can use the function :py:func:`datafusion.functions.array_empty` or `datafusion.functions.empty`.
8686
This function returns a boolean indicating whether the array is empty.
8787

8888
.. ipython:: python

python/datafusion/functions.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
"decode",
126126
"degrees",
127127
"digest",
128+
"empty",
128129
"encode",
129130
"ends_with",
130131
"exp",
@@ -1522,6 +1523,11 @@ def cardinality(array: Expr) -> Expr:
15221523
return Expr(f.cardinality(array.expr))
15231524

15241525

1526+
def empty(array: Expr) -> Expr:
1527+
"""This is an alias for :py:func:`array_empty`."""
1528+
return array_empty(array)
1529+
1530+
15251531
# aggregate functions
15261532
def approx_distinct(
15271533
expression: Expr,
@@ -2140,7 +2146,7 @@ def first_value(
21402146
expression: Argument to perform bitwise calculation on
21412147
filter: If provided, only compute against rows for which the filter is True
21422148
order_by: Set the ordering of the expression to evaluate
2143-
null_treatment: Assign whether to respect or ignull null values.
2149+
null_treatment: Assign whether to respect or ignore null values.
21442150
"""
21452151
order_by_raw = sort_list_to_raw_sort_list(order_by)
21462152
filter_raw = filter.expr if filter is not None else None
@@ -2172,7 +2178,7 @@ def last_value(
21722178
expression: Argument to perform bitwise calculation on
21732179
filter: If provided, only compute against rows for which the filter is True
21742180
order_by: Set the ordering of the expression to evaluate
2175-
null_treatment: Assign whether to respect or ignull null values.
2181+
null_treatment: Assign whether to respect or ignore null values.
21762182
"""
21772183
order_by_raw = sort_list_to_raw_sort_list(order_by)
21782184
filter_raw = filter.expr if filter is not None else None
@@ -2206,7 +2212,7 @@ def nth_value(
22062212
n: Index of value to return. Starts at 1.
22072213
filter: If provided, only compute against rows for which the filter is True
22082214
order_by: Set the ordering of the expression to evaluate
2209-
null_treatment: Assign whether to respect or ignull null values.
2215+
null_treatment: Assign whether to respect or ignore null values.
22102216
"""
22112217
order_by_raw = sort_list_to_raw_sort_list(order_by)
22122218
filter_raw = filter.expr if filter is not None else None

python/tests/test_functions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ def py_flatten(arr):
313313
lambda col: f.array_empty(col),
314314
lambda data: [len(r) == 0 for r in data],
315315
],
316+
[
317+
lambda col: f.empty(col),
318+
lambda data: [len(r) == 0 for r in data],
319+
],
316320
[
317321
lambda col: f.array_extract(col, literal(1)),
318322
lambda data: [r[0] for r in data],

0 commit comments

Comments
 (0)