Skip to content

Commit e8aa671

Browse files
authored
Move the udf module to user_defined (#1112)
* This is a breaking change to move the module datafusion.udf to datafusion.user_defined * Documentation updates to make the formatting more consistent with the rest of the site and to correct some errors when building the rst files using autoapi * Set async test parameters that generate a warning when unset in pytest * Add deprecation warning
1 parent 5a62c4b commit e8aa671

File tree

10 files changed

+788
-758
lines changed

10 files changed

+788
-758
lines changed

docs/source/conf.py

Lines changed: 1 addition & 0 deletions
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 generated files
7475

7576

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

docs/source/user-guide/common-operations/udf-and-udfa.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Scalar Functions
2626

2727
When writing a user-defined function that can operate on a row by row basis, these are called Scalar
2828
Functions. You can define your own scalar function by calling
29-
:py:func:`~datafusion.udf.ScalarUDF.udf` .
29+
:py:func:`~datafusion.user_defined.ScalarUDF.udf` .
3030

3131
The basic definition of a scalar UDF is a python function that takes one or more
3232
`pyarrow <https://arrow.apache.org/docs/python/index.html>`_ arrays and returns a single array as
@@ -93,9 +93,9 @@ converting to Python objects to do the evaluation.
9393
Aggregate Functions
9494
-------------------
9595

96-
The :py:func:`~datafusion.udf.AggregateUDF.udaf` function allows you to define User-Defined
96+
The :py:func:`~datafusion.user_defined.AggregateUDF.udaf` function allows you to define User-Defined
9797
Aggregate Functions (UDAFs). To use this you must implement an
98-
:py:class:`~datafusion.udf.Accumulator` that determines how the aggregation is performed.
98+
:py:class:`~datafusion.user_defined.Accumulator` that determines how the aggregation is performed.
9999

100100
When defining a UDAF there are four methods you need to implement. The ``update`` function takes the
101101
array(s) of input and updates the internal state of the accumulator. You should define this function
@@ -153,8 +153,8 @@ Window Functions
153153
----------------
154154

155155
To implement a User-Defined Window Function (UDWF) you must call the
156-
:py:func:`~datafusion.udf.WindowUDF.udwf` function using a class that implements the abstract
157-
class :py:class:`~datafusion.udf.WindowEvaluator`.
156+
:py:func:`~datafusion.user_defined.WindowUDF.udwf` function using a class that implements the abstract
157+
class :py:class:`~datafusion.user_defined.WindowEvaluator`.
158158

159159
There are three methods of evaluation of UDWFs.
160160

@@ -207,7 +207,7 @@ determine which evaluate functions are called.
207207
208208
import pyarrow as pa
209209
from datafusion import udwf, col, SessionContext
210-
from datafusion.udf import WindowEvaluator
210+
from datafusion.user_defined import WindowEvaluator
211211
212212
class ExponentialSmooth(WindowEvaluator):
213213
def __init__(self, alpha: float) -> None:

examples/python-udwf.py

Lines changed: 1 addition & 1 deletion
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.

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ exclude = [".github/**", "ci/**", ".asf.yaml"]
6363
locked = true
6464
features = ["substrait"]
6565

66+
[tool.pytest.ini_options]
67+
asyncio_mode = "auto"
68+
asyncio_default_fixture_loop_scope = "function"
69+
6670
# Enable docstring linting using the google style guide
6771
[tool.ruff.lint]
6872
select = ["ALL" ]

python/datafusion/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,15 @@
5151
from .io import read_avro, read_csv, read_json, read_parquet
5252
from .plan import ExecutionPlan, LogicalPlan
5353
from .record_batch import RecordBatch, RecordBatchStream
54-
from .udf import Accumulator, AggregateUDF, ScalarUDF, WindowUDF, udaf, udf, udwf
54+
from .user_defined import (
55+
Accumulator,
56+
AggregateUDF,
57+
ScalarUDF,
58+
WindowUDF,
59+
udaf,
60+
udf,
61+
udwf,
62+
)
5563

5664
__version__ = importlib_metadata.version(__name__)
5765

python/datafusion/context.py

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)