Skip to content

Commit c4b1e1b

Browse files
committed
Update documentation
1 parent f78eb05 commit c4b1e1b

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ 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+
Starting in DataFusion 49.0.0 you can also create slices of array elements using
86+
slice syntax from Python.
87+
88+
.. ipython:: python
89+
90+
df.select(col("a")[1:3].alias("second_two_elements"))
91+
8592
To check if an array is empty, you can use the function :py:func:`datafusion.functions.array_empty` or `datafusion.functions.empty`.
8693
This function returns a boolean indicating whether the array is empty.
8794

python/datafusion/expr.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,12 @@ def __getitem__(self, key: str | int | slice) -> Expr:
357357
358358
If ``key`` is a string, returns the subfield of the struct.
359359
If ``key`` is an integer, retrieves the element in the array. Note that the
360-
element index begins at ``0``, unlike `array_element` which begins at ``1``.
360+
element index begins at ``0``, unlike
361+
:py:func:`~datafusion.functions.array_element` which begins at ``1``.
362+
If ``key`` is a slice, returns an array that contains a slice of the
363+
original array. Similar to integer indexing, this follows Python convention
364+
where the index begins at ``0`` unlike
365+
:py:func:`~datafusion.functions.array_slice` which begins at ``1``.
361366
"""
362367
if isinstance(key, int):
363368
return Expr(

python/datafusion/functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2655,7 +2655,7 @@ def cume_dist(
26552655
"""Create a cumulative distribution window function.
26562656
26572657
This window function is similar to :py:func:`rank` except that the returned values
2658-
are the ratio of the row number to the total numebr of rows. Here is an example of a
2658+
are the ratio of the row number to the total number of rows. Here is an example of a
26592659
dataframe with a window ordered by descending ``points`` and the associated
26602660
cumulative distribution::
26612661

0 commit comments

Comments
 (0)