This is an automated email from the ASF dual-hosted git repository. timsaucer pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/datafusion-python.git
The following commit(s) were added to refs/heads/main by this push: new aedffe0 Add empty scalar function (alias of array_empty), fix a small typo (#938) aedffe0 is described below commit aedffe0d8a0522fa21a7b545aa885750f32fc218 Author: kosiew <kos...@gmail.com> AuthorDate: Fri Nov 1 19:42:57 2024 +0800 Add empty scalar function (alias of array_empty), fix a small typo (#938) * feat: add `empty` function as alias of array_empty * fix: correct typo in null_treatment parameter documentation --- docs/source/user-guide/common-operations/expressions.rst | 2 +- python/datafusion/functions.py | 12 +++++++++--- python/tests/test_functions.py | 4 ++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/docs/source/user-guide/common-operations/expressions.rst b/docs/source/user-guide/common-operations/expressions.rst index 23430d3..b2a83c8 100644 --- a/docs/source/user-guide/common-operations/expressions.rst +++ b/docs/source/user-guide/common-operations/expressions.rst @@ -82,7 +82,7 @@ approaches. Indexing an element of an array via ``[]`` starts at index 0 whereas :py:func:`~datafusion.functions.array_element` starts at index 1. -To check if an array is empty, you can use the function :py:func:`datafusion.functions.array_empty`. +To check if an array is empty, you can use the function :py:func:`datafusion.functions.array_empty` or `datafusion.functions.empty`. This function returns a boolean indicating whether the array is empty. .. ipython:: python diff --git a/python/datafusion/functions.py b/python/datafusion/functions.py index e67ba4a..907f801 100644 --- a/python/datafusion/functions.py +++ b/python/datafusion/functions.py @@ -125,6 +125,7 @@ __all__ = [ "decode", "degrees", "digest", + "empty", "encode", "ends_with", "exp", @@ -1522,6 +1523,11 @@ def cardinality(array: Expr) -> Expr: return Expr(f.cardinality(array.expr)) +def empty(array: Expr) -> Expr: + """This is an alias for :py:func:`array_empty`.""" + return array_empty(array) + + # aggregate functions def approx_distinct( expression: Expr, @@ -2140,7 +2146,7 @@ def first_value( expression: Argument to perform bitwise calculation on filter: If provided, only compute against rows for which the filter is True order_by: Set the ordering of the expression to evaluate - null_treatment: Assign whether to respect or ignull null values. + null_treatment: Assign whether to respect or ignore null values. """ order_by_raw = sort_list_to_raw_sort_list(order_by) filter_raw = filter.expr if filter is not None else None @@ -2172,7 +2178,7 @@ def last_value( expression: Argument to perform bitwise calculation on filter: If provided, only compute against rows for which the filter is True order_by: Set the ordering of the expression to evaluate - null_treatment: Assign whether to respect or ignull null values. + null_treatment: Assign whether to respect or ignore null values. """ order_by_raw = sort_list_to_raw_sort_list(order_by) filter_raw = filter.expr if filter is not None else None @@ -2206,7 +2212,7 @@ def nth_value( n: Index of value to return. Starts at 1. filter: If provided, only compute against rows for which the filter is True order_by: Set the ordering of the expression to evaluate - null_treatment: Assign whether to respect or ignull null values. + null_treatment: Assign whether to respect or ignore null values. """ order_by_raw = sort_list_to_raw_sort_list(order_by) filter_raw = filter.expr if filter is not None else None diff --git a/python/tests/test_functions.py b/python/tests/test_functions.py index 37943e5..c65c633 100644 --- a/python/tests/test_functions.py +++ b/python/tests/test_functions.py @@ -313,6 +313,10 @@ def py_flatten(arr): lambda col: f.array_empty(col), lambda data: [len(r) == 0 for r in data], ], + [ + lambda col: f.empty(col), + lambda data: [len(r) == 0 for r in data], + ], [ lambda col: f.array_extract(col, literal(1)), lambda data: [r[0] for r in data], --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@datafusion.apache.org For additional commands, e-mail: commits-h...@datafusion.apache.org