Skip to content

Commit b06f381

Browse files
committed
Move ffi-table-provider example to ffi-library and correct doc building
1 parent ae3bcda commit b06f381

File tree

17 files changed

+39
-40
lines changed

17 files changed

+39
-40
lines changed

.github/workflows/test.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ jobs:
9191
9292
- name: FFI unit tests
9393
run: |
94-
cd examples/ffi-table-provider
94+
cd examples/ffi-library
9595
uv run --no-project maturin develop --uv
9696
uv run --no-project pytest python/tests/_test_table_provider.py
9797

docs/source/conf.py

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
autoapi_member_order = "groupwise"
7272
suppress_warnings = ["autoapi.python_import_resolution"]
7373
autoapi_python_class_content = "both"
74+
autoapi_keep_files = False # Set to True for debugging documentation generated
7475

7576

7677
def autoapi_skip_member_fn(app, what, name, obj, skip, options) -> bool: # noqa: ARG001

docs/source/contributor-guide/ffi.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ By convention the ``datafusion-python`` library expects a Python object that has
176176
``TableProvider`` PyCapsule to have this capsule accessible by calling a function named
177177
``__datafusion_table_provider__``. You can see a complete working example of how to
178178
share a ``TableProvider`` from one python library to DataFusion Python in the
179-
`repository examples folder <https://github.com/apache/datafusion-python/tree/main/examples/ffi-table-provider>`_.
179+
`repository examples folder <https://github.com/apache/datafusion-python/tree/main/examples/ffi-library>`_.
180180

181181
This section has been written using ``TableProvider`` as an example. It is the first
182182
extension that has been written using this approach and the most thoroughly implemented.

examples/ffi-table-provider/Cargo.toml renamed to examples/ffi-library/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# under the License.
1717

1818
[package]
19-
name = "ffi-table-provider"
19+
name = "ffi-library"
2020
version = "0.1.0"
2121
edition = "2021"
2222

File renamed without changes.

examples/python-udwf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from datafusion import col, lit, udwf
2323
from datafusion import functions as f
2424
from datafusion.expr import WindowFrame
25-
from datafusion.udf import WindowEvaluator
25+
from datafusion.user_defined import WindowEvaluator
2626

2727
# This example creates five different examples of user defined window functions in order
2828
# to demonstrate the variety of ways a user may need to implement.

python/datafusion/__init__.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,15 @@
4848
from .io import read_avro, read_csv, read_json, read_parquet
4949
from .plan import ExecutionPlan, LogicalPlan
5050
from .record_batch import RecordBatch, RecordBatchStream
51-
from .udf import Accumulator, AggregateUDF, ScalarUDF, WindowUDF, udaf, udf, udwf
51+
from .user_defined import (
52+
Accumulator,
53+
AggregateUDF,
54+
ScalarUDF,
55+
WindowUDF,
56+
udaf,
57+
udf,
58+
udwf,
59+
)
5260

5361
__version__ = importlib_metadata.version(__name__)
5462

python/datafusion/context.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from datafusion.dataframe import DataFrame
3131
from datafusion.expr import Expr, SortExpr, sort_list_to_raw_sort_list
3232
from datafusion.record_batch import RecordBatchStream
33-
from datafusion.udf import AggregateUDF, ScalarUDF, WindowUDF
33+
from datafusion.user_defined import AggregateUDF, ScalarUDF, WindowUDF
3434

3535
from ._internal import RuntimeEnvBuilder as RuntimeEnvBuilderInternal
3636
from ._internal import SessionConfig as SessionConfigInternal

python/datafusion/udf.py renamed to python/datafusion/user_defined.py

+21-31
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,9 @@ def udf(*args: Any, **kwargs: Any): # noqa: D417
153153
This class can be used both as a **function** and as a **decorator**.
154154
155155
Usage:
156-
- **As a function**: Call `udf(func, input_types, return_type, volatility,
157-
name)`.
158-
- **As a decorator**: Use `@udf(input_types, return_type, volatility,
159-
name)`. In this case, do **not** pass `func` explicitly.
156+
- **As a function**: Call :py:func:`udf(func, input_types, return_type, volatility, name)`.
157+
- **As a decorator**: Use :py:func:`@udf(input_types, return_type, volatility, name)`.
158+
In this case, do **not** pass `func` explicitly.
160159
161160
Args:
162161
func (Callable, optional): **Only needed when calling as a function.**
@@ -175,9 +174,8 @@ def udf(*args: Any, **kwargs: Any): # noqa: D417
175174
A user-defined function that can be used in SQL expressions,
176175
data aggregation, or window function calls.
177176
178-
Example:
179-
**Using `udf` as a function:**
180-
```
177+
Example: **Using `udf` as a function**::
178+
181179
def double_func(x):
182180
return x * 2
183181
double_udf = udf(double_func, [pa.int32()], pa.int32(),
@@ -189,8 +187,7 @@ def double_func(x):
189187
@udf([pa.int32()], pa.int32(), "volatile", "double_it")
190188
def double_udf(x):
191189
return x * 2
192-
```
193-
"""
190+
""" # noqa: E501 W505
194191

195192
def _function(
196193
func: Callable[..., _R],
@@ -348,20 +345,18 @@ def udaf(*args: Any, **kwargs: Any): # noqa: D417
348345
data aggregation or window function calls.
349346
350347
Usage:
351-
- **As a function**: Call `udaf(accum, input_types, return_type, state_type,
352-
volatility, name)`.
353-
- **As a decorator**: Use `@udaf(input_types, return_type, state_type,
354-
volatility, name)`.
355-
When using `udaf` as a decorator, **do not pass `accum` explicitly**.
348+
- **As a function**: Call :py:func:`udaf(accum, input_types, return_type, state_type, volatility, name)`.
349+
- **As a decorator**: Use :py:func:`@udaf(input_types, return_type, state_type, volatility, name)`.
350+
When using `udaf` as a decorator, **do not pass `accum` explicitly**.
356351
357352
**Function example:**
358353
359-
If your `:py:class:Accumulator` can be instantiated with no arguments, you
360-
can simply pass it's type as `accum`. If you need to pass additional
361-
arguments to it's constructor, you can define a lambda or a factory method.
362-
During runtime the `:py:class:Accumulator` will be constructed for every
363-
instance in which this UDAF is used. The following examples are all valid.
364-
```
354+
If your :py:class:`Accumulator` can be instantiated with no arguments, you
355+
can simply pass it's type as `accum`. If you need to pass additional
356+
arguments to it's constructor, you can define a lambda or a factory method.
357+
During runtime the :py:class:`Accumulator` will be constructed for every
358+
instance in which this UDAF is used. The following examples are all valid::
359+
365360
import pyarrow as pa
366361
import pyarrow.compute as pc
367362
@@ -390,14 +385,12 @@ def sum_bias_10() -> Summarize:
390385
"immutable")
391386
udaf3 = udaf(lambda: Summarize(20.0), pa.float64(), pa.float64(),
392387
[pa.float64()], "immutable")
393-
```
394388
395-
**Decorator example:**
396-
```
389+
**Decorator example:**::
390+
397391
@udaf(pa.float64(), pa.float64(), [pa.float64()], "immutable")
398392
def udf4() -> Summarize:
399393
return Summarize(10.0)
400-
```
401394
402395
Args:
403396
accum: The accumulator python function. **Only needed when calling as a
@@ -411,7 +404,7 @@ def udf4() -> Summarize:
411404
Returns:
412405
A user-defined aggregate function, which can be used in either data
413406
aggregation or window function calls.
414-
"""
407+
""" # noqa: E501 W505
415408

416409
def _function(
417410
accum: Callable[[], Accumulator],
@@ -691,8 +684,8 @@ def udwf(*args: Any, **kwargs: Any): # noqa: D417
691684
name)`. When using `udwf` as a decorator, **do not pass `func`
692685
explicitly**.
693686
694-
**Function example:**
695-
```
687+
**Function example:**::
688+
696689
import pyarrow as pa
697690
698691
class BiasedNumbers(WindowEvaluator):
@@ -710,14 +703,11 @@ def bias_10() -> BiasedNumbers:
710703
udwf2 = udwf(bias_10, pa.int64(), pa.int64(), "immutable")
711704
udwf3 = udwf(lambda: BiasedNumbers(20), pa.int64(), pa.int64(), "immutable")
712705
713-
```
706+
**Decorator example:**::
714707
715-
**Decorator example:**
716-
```
717708
@udwf(pa.int64(), pa.int64(), "immutable")
718709
def biased_numbers() -> BiasedNumbers:
719710
return BiasedNumbers(10)
720-
```
721711
722712
Args:
723713
func: **Only needed when calling as a function. Skip this argument when

python/tests/test_imports.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def test_class_module_is_datafusion():
107107
AggregateUDF,
108108
ScalarUDF,
109109
]:
110-
assert klass.__module__ == "datafusion.udf"
110+
assert klass.__module__ == "datafusion.user_defined"
111111

112112
# expressions
113113
for klass in [Expr, Column, Literal, BinaryExpr, AggregateFunction]:

python/tests/test_udwf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from datafusion import SessionContext, column, lit, udwf
2323
from datafusion import functions as f
2424
from datafusion.expr import WindowFrame
25-
from datafusion.udf import WindowEvaluator
25+
from datafusion.user_defined import WindowEvaluator
2626

2727

2828
class ExponentialSmoothDefault(WindowEvaluator):

src/dataframe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ fn record_batch_into_schema(
835835
) -> Result<RecordBatch, ArrowError> {
836836
let schema = Arc::new(schema.clone());
837837
let base_schema = record_batch.schema();
838-
if base_schema.fields().len() == 0 {
838+
if base_schema.fields().is_empty() {
839839
// Nothing to project
840840
return Ok(RecordBatch::new_empty(schema));
841841
}

0 commit comments

Comments
 (0)