This is an automated email from the ASF dual-hosted git repository.
timsaucer pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-python.git
The following commit(s) were added to refs/heads/main by this push:
new 79c22d6 Search default window functions if no session context was
provided (#963)
79c22d6 is described below
commit 79c22d6d6c0809e7e93a0a23249baa516dbd8d6f
Author: Tim Saucer <[email protected]>
AuthorDate: Wed Dec 4 05:56:11 2024 -0500
Search default window functions if no session context was provided (#963)
* Search default window functions if no session context was provided
* Check if value is None because [] don't trigger the intended behavior
---
python/datafusion/dataframe.py | 6 +++---
python/datafusion/functions.py | 1 +
src/functions.rs | 11 +++++++++++
3 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/python/datafusion/dataframe.py b/python/datafusion/dataframe.py
index e283f59..0b38db9 100644
--- a/python/datafusion/dataframe.py
+++ b/python/datafusion/dataframe.py
@@ -446,14 +446,14 @@ class DataFrame:
left_on = join_keys[0]
right_on = join_keys[1]
- if on:
- if left_on or right_on:
+ if on is not None:
+ if left_on is not None or right_on is not None:
raise ValueError(
"`left_on` or `right_on` should not provided with `on`"
)
left_on = on
right_on = on
- elif left_on or right_on:
+ elif left_on is not None or right_on is not None:
if left_on is None or right_on is None:
raise ValueError("`left_on` and `right_on` should both be
provided.")
else:
diff --git a/python/datafusion/functions.py b/python/datafusion/functions.py
index 15ad882..f3ee5c0 100644
--- a/python/datafusion/functions.py
+++ b/python/datafusion/functions.py
@@ -431,6 +431,7 @@ def window(
partition_by = expr_list_to_raw_expr_list(partition_by)
order_by_raw = sort_list_to_raw_sort_list(order_by)
window_frame = window_frame.window_frame if window_frame is not None else
None
+ ctx = ctx.ctx if ctx is not None else None
return Expr(f.window(name, args, partition_by, order_by_raw, window_frame,
ctx))
diff --git a/src/functions.rs b/src/functions.rs
index e29c57f..5c45028 100644
--- a/src/functions.rs
+++ b/src/functions.rs
@@ -16,6 +16,7 @@
// under the License.
use datafusion::functions_aggregate::all_default_aggregate_functions;
+use datafusion::functions_window::all_default_window_functions;
use datafusion::logical_expr::ExprFunctionExt;
use datafusion::logical_expr::WindowFrame;
use pyo3::{prelude::*, wrap_pyfunction};
@@ -282,6 +283,16 @@ fn find_window_fn(name: &str, ctx:
Option<PySessionContext>) -> PyResult<WindowF
return Ok(agg_fn);
}
+ // search default window functions
+ let window_fn = all_default_window_functions()
+ .iter()
+ .find(|v| v.name() == name || v.aliases().contains(&name.to_string()))
+ .map(|f| WindowFunctionDefinition::WindowUDF(f.clone()));
+
+ if let Some(window_fn) = window_fn {
+ return Ok(window_fn);
+ }
+
Err(DataFusionError::Common(format!("window function `{name}` not
found")).into())
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]