diff --git a/pyo3-polars-derive/src/lib.rs b/pyo3-polars-derive/src/lib.rs index 166708c..097196e 100644 --- a/pyo3-polars-derive/src/lib.rs +++ b/pyo3-polars-derive/src/lib.rs @@ -241,7 +241,7 @@ fn create_field_function( match result { Ok(out) => { - let out = polars_core::export::arrow::ffi::export_field_to_c(&out.to_arrow(true)); + let out = polars_core::export::arrow::ffi::export_field_to_c(&out.to_arrow(CompatLevel::newest())); *return_value = out; }, Err(err) => { @@ -278,7 +278,7 @@ fn create_field_function_from_with_dtype( let mapper = polars_plan::dsl::FieldsMapper::new(&inputs); let dtype = polars_core::datatypes::DataType::#dtype; let out = mapper.with_dtype(dtype).unwrap(); - let out = polars_core::export::arrow::ffi::export_field_to_c(&out.to_arrow(true)); + let out = polars_core::export::arrow::ffi::export_field_to_c(&out.to_arrow(CompatLevel::newest())); *return_value = out; } ) diff --git a/pyo3-polars/src/error.rs b/pyo3-polars/src/error.rs index de46c4c..9a55bc6 100644 --- a/pyo3-polars/src/error.rs +++ b/pyo3-polars/src/error.rs @@ -36,12 +36,8 @@ impl std::convert::From for PyErr { PolarsError::StringCacheMismatch(err) => { StringCacheMismatchError::new_err(err.to_string()) } - PolarsError::SQLInterface(err) => { - SQLInterface::new_err(err.to_string()) - }, - PolarsError::SQLSyntax(err) => { - SQLSyntax::new_err(err.to_string()) - } + PolarsError::SQLInterface(err) => SQLInterface::new_err(err.to_string()), + PolarsError::SQLSyntax(err) => SQLSyntax::new_err(err.to_string()), PolarsError::Context { error, .. } => convert(error), } } diff --git a/pyo3-polars/src/lib.rs b/pyo3-polars/src/lib.rs index f2e4ca3..c627b48 100644 --- a/pyo3-polars/src/lib.rs +++ b/pyo3-polars/src/lib.rs @@ -170,10 +170,18 @@ impl IntoPy for PySeries { match s.getattr("_import_from_c") { // Go via polars Ok(import_from_c) => { + // Get supported compatibility level + let compat_level = CompatLevel::with_level( + s.getattr("_newest_compat_level") + .map_or(1, |newest_compat_level| { + newest_compat_level.call0().unwrap().extract().unwrap() + }), + ) + .unwrap_or(CompatLevel::newest()); // Prepare pointers on the heap. let mut chunk_ptrs = Vec::with_capacity(self.0.n_chunks()); for i in 0..self.0.n_chunks() { - let array = self.0.to_arrow(i, true); + let array = self.0.to_arrow(i, compat_level); let schema = Box::leak(Box::new(arrow::ffi::export_field_to_c( &ArrowField::new("", array.data_type().clone(), true), ))); @@ -210,7 +218,7 @@ impl IntoPy for PySeries { Err(_) => { let s = self.0.rechunk(); let name = s.name(); - let arr = s.to_arrow(0, false); + let arr = s.to_arrow(0, CompatLevel::oldest()); let pyarrow = py.import_bound("pyarrow").expect("pyarrow not installed"); let arg = to_py_array(arr, py, pyarrow).unwrap();