Skip to content

Commit

Permalink
fix pyo3 warnings
Browse files Browse the repository at this point in the history
Implicit defaults for trailing optional arguments have been deprecated
in pyo3 v0.22.0 PyO3/pyo3#4078
  • Loading branch information
emgeee committed Sep 10, 2024
1 parent f2b3d3b commit 4b45a4b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/common/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use pyo3::{exceptions::PyValueError, prelude::*};
use crate::errors::py_datafusion_err;

#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[pyclass(name = "RexType", module = "datafusion.common")]
#[pyclass(eq, eq_int, name = "RexType", module = "datafusion.common")]
pub enum RexType {
Alias,
Literal,
Expand Down Expand Up @@ -692,7 +692,7 @@ impl From<DataType> for PyDataType {

/// Represents the possible Python types that can be mapped to the SQL types
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[pyclass(name = "PythonType", module = "datafusion.common")]
#[pyclass(eq, eq_int, name = "PythonType", module = "datafusion.common")]
pub enum PythonType {
Array,
Bool,
Expand All @@ -712,7 +712,7 @@ pub enum PythonType {
#[allow(non_camel_case_types)]
#[allow(clippy::upper_case_acronyms)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[pyclass(name = "SqlType", module = "datafusion.common")]
#[pyclass(eq, eq_int, name = "SqlType", module = "datafusion.common")]
pub enum SqlType {
ANY,
ARRAY,
Expand Down Expand Up @@ -770,7 +770,7 @@ pub enum SqlType {
#[allow(non_camel_case_types)]
#[allow(clippy::upper_case_acronyms)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[pyclass(name = "NullTreatment", module = "datafusion.common")]
#[pyclass(eq, eq_int, name = "NullTreatment", module = "datafusion.common")]
pub enum NullTreatment {
IGNORE_NULLS,
RESPECT_NULLS,
Expand Down
1 change: 1 addition & 0 deletions src/common/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub struct SqlTable {
#[pymethods]
impl SqlTable {
#[new]
#[pyo3(signature = (table_name, columns, row_count, filepaths=None))]
pub fn new(
table_name: String,
columns: Vec<(String, DataTypeMap)>,
Expand Down
8 changes: 8 additions & 0 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ impl PySessionContext {
}

/// Register an object store with the given name
#[pyo3(signature = (scheme, store, host=None))]
pub fn register_object_store(
&mut self,
scheme: &str,
Expand Down Expand Up @@ -374,6 +375,7 @@ impl PySessionContext {
Ok(PyDataFrame::new(df))
}

#[pyo3(signature = (query, options=None))]
pub fn sql_with_options(
&mut self,
query: &str,
Expand All @@ -390,6 +392,7 @@ impl PySessionContext {
Ok(PyDataFrame::new(df))
}

#[pyo3(signature = (partitions, name=None, schema=None))]
pub fn create_dataframe(
&mut self,
partitions: PyArrowType<Vec<Vec<RecordBatch>>>,
Expand Down Expand Up @@ -433,6 +436,7 @@ impl PySessionContext {
}

/// Construct datafusion dataframe from Python list
#[pyo3(signature = (data, name=None))]
pub fn from_pylist(
&mut self,
data: Bound<'_, PyList>,
Expand All @@ -452,6 +456,7 @@ impl PySessionContext {
}

/// Construct datafusion dataframe from Python dictionary
#[pyo3(signature = (data, name=None))]
pub fn from_pydict(
&mut self,
data: Bound<'_, PyDict>,
Expand All @@ -471,6 +476,7 @@ impl PySessionContext {
}

/// Construct datafusion dataframe from Arrow Table
#[pyo3(signature = (data, name=None))]
pub fn from_arrow(
&mut self,
data: Bound<'_, PyAny>,
Expand Down Expand Up @@ -506,6 +512,7 @@ impl PySessionContext {

/// Construct datafusion dataframe from pandas
#[allow(clippy::wrong_self_convention)]
#[pyo3(signature = (data, name=None))]
pub fn from_pandas(
&mut self,
data: Bound<'_, PyAny>,
Expand All @@ -525,6 +532,7 @@ impl PySessionContext {
}

/// Construct datafusion dataframe from polars
#[pyo3(signature = (data, name=None))]
pub fn from_polars(
&mut self,
data: Bound<'_, PyAny>,
Expand Down
1 change: 1 addition & 0 deletions src/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ impl PyDataFrame {
Ok(table)
}

#[pyo3(signature = (requested_schema=None))]
fn __arrow_c_stream__<'py>(
&'py mut self,
py: Python<'py>,
Expand Down
20 changes: 20 additions & 0 deletions src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ fn array_cat(exprs: Vec<PyExpr>) -> PyExpr {
}

#[pyfunction]
#[pyo3(signature = (array, element, index=None))]
fn array_position(array: PyExpr, element: PyExpr, index: Option<i64>) -> PyExpr {
let index = ScalarValue::Int64(index);
let index = Expr::Literal(index);
Expand All @@ -104,6 +105,7 @@ fn array_position(array: PyExpr, element: PyExpr, index: Option<i64>) -> PyExpr
}

#[pyfunction]
#[pyo3(signature = (array, begin, end, stride=None))]
fn array_slice(array: PyExpr, begin: PyExpr, end: PyExpr, stride: Option<PyExpr>) -> PyExpr {
datafusion::functions_nested::expr_fn::array_slice(
array.into(),
Expand Down Expand Up @@ -142,16 +144,19 @@ fn concat_ws(sep: String, args: Vec<PyExpr>) -> PyResult<PyExpr> {
}

#[pyfunction]
#[pyo3(signature = (values, regex, flags=None))]
fn regexp_like(values: PyExpr, regex: PyExpr, flags: Option<PyExpr>) -> PyResult<PyExpr> {
Ok(functions::expr_fn::regexp_like(values.expr, regex.expr, flags.map(|x| x.expr)).into())
}

#[pyfunction]
#[pyo3(signature = (values, regex, flags=None))]
fn regexp_match(values: PyExpr, regex: PyExpr, flags: Option<PyExpr>) -> PyResult<PyExpr> {
Ok(functions::expr_fn::regexp_match(values.expr, regex.expr, flags.map(|x| x.expr)).into())
}

#[pyfunction]
#[pyo3(signature = (string, pattern, replacement, flags=None))]
/// Replaces substring(s) matching a POSIX regular expression.
fn regexp_replace(
string: PyExpr,
Expand Down Expand Up @@ -283,6 +288,7 @@ fn find_window_fn(name: &str, ctx: Option<PySessionContext>) -> PyResult<WindowF

/// Creates a new Window function expression
#[pyfunction]
#[pyo3(signature = (name, args, partition_by=None, order_by=None, window_frame=None, ctx=None))]
fn window(
name: &str,
args: Vec<PyExpr>,
Expand Down Expand Up @@ -331,6 +337,7 @@ macro_rules! aggregate_function {
};
($NAME: ident, $($arg:ident)*) => {
#[pyfunction]
#[pyo3(signature = ($($arg),*, distinct=None, filter=None, order_by=None, null_treatment=None))]
fn $NAME(
$($arg: PyExpr),*,
distinct: Option<bool>,
Expand All @@ -351,6 +358,7 @@ macro_rules! aggregate_function_vec_args {
};
($NAME: ident, $($arg:ident)*) => {
#[pyfunction]
#[pyo3(signature = ($($arg),*, distinct=None, filter=None, order_by=None, null_treatment=None))]
fn $NAME(
$($arg: PyExpr),*,
distinct: Option<bool>,
Expand Down Expand Up @@ -624,6 +632,7 @@ aggregate_function!(approx_median);
// aggregate_function!(grouping);

#[pyfunction]
#[pyo3(signature = (expression, percentile, num_centroids=None, filter=None))]
pub fn approx_percentile_cont(
expression: PyExpr,
percentile: f64,
Expand All @@ -642,6 +651,7 @@ pub fn approx_percentile_cont(
}

#[pyfunction]
#[pyo3(signature = (expression, weight, percentile, filter=None))]
pub fn approx_percentile_cont_with_weight(
expression: PyExpr,
weight: PyExpr,
Expand All @@ -662,6 +672,7 @@ aggregate_function_vec_args!(last_value);
// We handle first_value explicitly because the signature expects an order_by
// https://github.com/apache/datafusion/issues/12376
#[pyfunction]
#[pyo3(signature = (expr, distinct=None, filter=None, order_by=None, null_treatment=None))]
pub fn first_value(
expr: PyExpr,
distinct: Option<bool>,
Expand All @@ -677,6 +688,7 @@ pub fn first_value(

// nth_value requires a non-expr argument
#[pyfunction]
#[pyo3(signature = (expr, n, distinct=None, filter=None, order_by=None, null_treatment=None))]
pub fn nth_value(
expr: PyExpr,
n: i64,
Expand All @@ -691,6 +703,7 @@ pub fn nth_value(

// string_agg requires a non-expr argument
#[pyfunction]
#[pyo3(signature = (expr, delimiter, distinct=None, filter=None, order_by=None, null_treatment=None))]
pub fn string_agg(
expr: PyExpr,
delimiter: String,
Expand Down Expand Up @@ -730,6 +743,7 @@ fn add_builder_fns_to_window(
}

#[pyfunction]
#[pyo3(signature = (arg, shift_offset, default_value=None, partition_by=None, order_by=None))]
pub fn lead(
arg: PyExpr,
shift_offset: i64,
Expand All @@ -743,6 +757,7 @@ pub fn lead(
}

#[pyfunction]
#[pyo3(signature = (arg, shift_offset, default_value=None, partition_by=None, order_by=None))]
pub fn lag(
arg: PyExpr,
shift_offset: i64,
Expand All @@ -756,13 +771,15 @@ pub fn lag(
}

#[pyfunction]
#[pyo3(signature = (partition_by=None, order_by=None))]
pub fn rank(partition_by: Option<Vec<PyExpr>>, order_by: Option<Vec<PyExpr>>) -> PyResult<PyExpr> {
let window_fn = window_function::rank();

add_builder_fns_to_window(window_fn, partition_by, order_by)
}

#[pyfunction]
#[pyo3(signature = (partition_by=None, order_by=None))]
pub fn dense_rank(
partition_by: Option<Vec<PyExpr>>,
order_by: Option<Vec<PyExpr>>,
Expand All @@ -773,6 +790,7 @@ pub fn dense_rank(
}

#[pyfunction]
#[pyo3(signature = (partition_by=None, order_by=None))]
pub fn percent_rank(
partition_by: Option<Vec<PyExpr>>,
order_by: Option<Vec<PyExpr>>,
Expand All @@ -783,6 +801,7 @@ pub fn percent_rank(
}

#[pyfunction]
#[pyo3(signature = (partition_by=None, order_by=None))]
pub fn cume_dist(
partition_by: Option<Vec<PyExpr>>,
order_by: Option<Vec<PyExpr>>,
Expand All @@ -793,6 +812,7 @@ pub fn cume_dist(
}

#[pyfunction]
#[pyo3(signature = (arg, partition_by=None, order_by=None))]
pub fn ntile(
arg: PyExpr,
partition_by: Option<Vec<PyExpr>>,
Expand Down

0 comments on commit 4b45a4b

Please sign in to comment.