Skip to content

Commit 80e88f8

Browse files
committed
chore: document Expr.__getitem__ (get a field of a struct array)
Signed-off-by: Daniel King <[email protected]>
1 parent 5405737 commit 80e88f8

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

docs/api/python/expr.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,36 @@ the following expression represents the set of rows for which the `age` column l
3232
.. autofunction:: vortex.expr.literal
3333

3434
.. autoclass:: vortex.expr.Expr
35+
:members:
36+
37+
.. py:method:: __getitem__(name, /)
38+
39+
Extract a field of a struct array.
40+
41+
:parameters:
42+
43+
- **name** (:class:`.str`) -- The name of the field.
44+
45+
:return type:
46+
47+
:class:`.vortex.Expr`
48+
49+
.. rubric:: Examples
50+
51+
>>> import vortex as vx
52+
>>> import vortex.expr as ve
53+
>>> import pyarrow as pa
54+
>>>
55+
>>> array = pa.array([
56+
... {"x": 1, "y": {"yy": "a"}},
57+
... {"x": 2, "y": {"yy": "b"}},
58+
... ])
59+
>>>
60+
>>> vx.io.write(vx.array(array), '/tmp/foo.vortex')
61+
>>> (vx.file.open('/tmp/foo.vortex')
62+
... .scan(expr=vx.expr.column("y")["yy"] == "a")
63+
... .read_all()
64+
... .to_pylist()
65+
... )
66+
[{'x': 1, 'y': {'yy': 'a'}}]
67+

vortex-python/src/expr/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ impl PyExpr {
159159
py_binary_operator(self_, Operator::Or, coerce_expr(right)?)
160160
}
161161

162+
// Special methods docstrings cannot be defined in Rust. Write a docstring in the corresponding
163+
// rST file. https://github.com/PyO3/pyo3/issues/4326
162164
fn __getitem__(self_: PyRef<'_, Self>, field: String) -> PyResult<PyExpr> {
163165
get_item(field, self_.clone())
164166
}

0 commit comments

Comments
 (0)