Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
run: |
source venv/bin/activate
flake8 python --ignore=E501
black --line-length 79 --check python
black --line-length 79 --diff --check python
- name: Run tests
run: |
source venv/bin/activate
Expand Down
13 changes: 6 additions & 7 deletions docs/source/python/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ Simple usage:
.. code-block:: python

import datafusion
from datafusion import functions as f
from datafusion import col
import pyarrow

# an alias
f = datafusion.functions

# create a context
ctx = datafusion.ExecutionContext()

Expand All @@ -56,8 +55,8 @@ Simple usage:

# create a new statement
df = df.select(
f.col("a") + f.col("b"),
f.col("a") - f.col("b"),
col("a") + col("b"),
col("a") - col("b"),
)

# execute and collect the first (and only) batch
Expand All @@ -77,7 +76,7 @@ UDFs

udf = f.udf(is_null, [pyarrow.int64()], pyarrow.bool_())

df = df.select(udf(f.col("a")))
df = df.select(udf(col("a")))


UDAF
Expand Down Expand Up @@ -117,7 +116,7 @@ UDAF

df = df.aggregate(
[],
[udaf(f.col("a"))]
[udaf(col("a"))]
)


Expand Down
7 changes: 7 additions & 0 deletions python/datafusion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
ScalarUDF,
)


__all__ = [
"DataFrame",
"ExecutionContext",
Expand Down Expand Up @@ -61,12 +62,18 @@ def column(value):
return Expression.column(value)


col = column


def literal(value):
if not isinstance(value, pa.Scalar):
value = pa.scalar(value)
return Expression.literal(value)


lit = literal


def udf(func, input_types, return_type, volatility, name=None):
"""
Create a new User Defined Function
Expand Down
4 changes: 4 additions & 0 deletions python/src/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ impl PyObjectProtocol for PyExpr {
};
expr.into()
}

fn __str__(&self) -> PyResult<String> {
Ok(format!("{}", self.expr))
}
}

#[pymethods]
Expand Down