Skip to content

Commit

Permalink
fix: Py-polars compilation with no features (pola-rs#18129)
Browse files Browse the repository at this point in the history
  • Loading branch information
coastalwhite authored Aug 10, 2024
1 parent bc65bd0 commit d1e0f63
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 21 deletions.
7 changes: 6 additions & 1 deletion py-polars/src/dataframe/general.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::mem::ManuallyDrop;

use either::Either;
use polars::export::arrow::bitmap::MutableBitmap;
use polars::prelude::*;
Expand Down Expand Up @@ -608,7 +610,10 @@ impl PyDataFrame {
// underneath of you, so don't use this anywhere else.
let mut df = std::mem::take(&mut self.df);
let cols = unsafe { std::mem::take(df.get_columns_mut()) };
let (ptr, len, cap) = cols.into_raw_parts();
let mut md_cols = ManuallyDrop::new(cols);
let ptr = md_cols.as_mut_ptr();
let len = md_cols.len();
let cap = md_cols.capacity();
(ptr as usize, len, cap)
}
}
55 changes: 36 additions & 19 deletions py-polars/src/lazyframe/visitor/expr_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use polars_core::series::IsSorted;
use polars_ops::prelude::ClosedInterval;
use polars_plan::dsl::function_expr::rolling::RollingFunction;
use polars_plan::dsl::function_expr::rolling_by::RollingFunctionBy;
use polars_plan::dsl::function_expr::trigonometry::TrigonometricFunction;
use polars_plan::dsl::{BooleanFunction, StringFunction, TemporalFunction};
use polars_plan::prelude::{
AExpr, FunctionExpr, GroupbyOptions, IRAggExpr, LiteralValue, Operator, PowFunction,
Expand Down Expand Up @@ -773,6 +772,7 @@ pub(crate) fn into_py(py: Python<'_>, expr: &AExpr) -> PyResult<PyObject> {
ignore_nulls,
)
.to_object(py),
#[cfg(feature = "regex")]
StringFunction::Contains { literal, strict } => {
(PyStringFunction::Contains.into_py(py), literal, strict).to_object(py)
},
Expand All @@ -795,6 +795,7 @@ pub(crate) fn into_py(py: Python<'_>, expr: &AExpr) -> PyResult<PyObject> {
pat,
)
.to_object(py),
#[cfg(feature = "regex")]
StringFunction::Find { literal, strict } => {
(PyStringFunction::Find.into_py(py), literal, strict).to_object(py)
},
Expand All @@ -819,6 +820,7 @@ pub(crate) fn into_py(py: Python<'_>, expr: &AExpr) -> PyResult<PyObject> {
StringFunction::JsonPathMatch => {
(PyStringFunction::JsonPathMatch.into_py(py),).to_object(py)
},
#[cfg(feature = "regex")]
StringFunction::Replace { n, literal } => {
(PyStringFunction::Replace.into_py(py), n, literal).to_object(py)
},
Expand All @@ -837,12 +839,14 @@ pub(crate) fn into_py(py: Python<'_>, expr: &AExpr) -> PyResult<PyObject> {
StringFunction::HexEncode => {
(PyStringFunction::HexEncode.into_py(py),).to_object(py)
},
#[cfg(feature = "binary_encoding")]
StringFunction::HexDecode(strict) => {
(PyStringFunction::HexDecode.into_py(py), strict).to_object(py)
},
StringFunction::Base64Encode => {
(PyStringFunction::Base64Encode.into_py(py),).to_object(py)
},
#[cfg(feature = "binary_encoding")]
StringFunction::Base64Decode(strict) => {
(PyStringFunction::Base64Decode.into_py(py), strict).to_object(py)
},
Expand Down Expand Up @@ -887,6 +891,7 @@ pub(crate) fn into_py(py: Python<'_>, expr: &AExpr) -> PyResult<PyObject> {
StringFunction::ToDecimal(inference_length) => {
(PyStringFunction::ToDecimal.into_py(py), inference_length).to_object(py)
},
#[cfg(feature = "nightly")]
StringFunction::Titlecase => {
(PyStringFunction::Titlecase.into_py(py),).to_object(py)
},
Expand Down Expand Up @@ -968,6 +973,7 @@ pub(crate) fn into_py(py: Python<'_>, expr: &AExpr) -> PyResult<PyObject> {
TemporalFunction::WithTimeUnit(time_unit) => {
(PyTemporalFunction::WithTimeUnit, Wrap(*time_unit)).into_py(py)
},
#[cfg(feature = "timezones")]
TemporalFunction::ConvertTimeZone(time_zone) => {
(PyTemporalFunction::ConvertTimeZone, time_zone).into_py(py)
},
Expand All @@ -978,11 +984,14 @@ pub(crate) fn into_py(py: Python<'_>, expr: &AExpr) -> PyResult<PyObject> {
TemporalFunction::OffsetBy => (PyTemporalFunction::OffsetBy,).into_py(py),
TemporalFunction::MonthStart => (PyTemporalFunction::MonthStart,).into_py(py),
TemporalFunction::MonthEnd => (PyTemporalFunction::MonthEnd,).into_py(py),
#[cfg(feature = "timezones")]
TemporalFunction::BaseUtcOffset => {
(PyTemporalFunction::BaseUtcOffset,).into_py(py)
},
#[cfg(feature = "timezones")]
TemporalFunction::DSTOffset => (PyTemporalFunction::DSTOffset,).into_py(py),
TemporalFunction::Round => (PyTemporalFunction::Round,).into_py(py),
#[cfg(feature = "timezones")]
TemporalFunction::ReplaceTimeZone(time_zone, non_existent) => (
PyTemporalFunction::ReplaceTimeZone,
time_zone
Expand Down Expand Up @@ -1033,6 +1042,7 @@ pub(crate) fn into_py(py: Python<'_>, expr: &AExpr) -> PyResult<PyObject> {
BooleanFunction::IsBetween { closed } => {
(PyBooleanFunction::IsBetween, Wrap(*closed)).into_py(py)
},
#[cfg(feature = "is_in")]
BooleanFunction::IsIn => (PyBooleanFunction::IsIn,).into_py(py),
BooleanFunction::AllHorizontal => {
(PyBooleanFunction::AllHorizontal,).into_py(py)
Expand Down Expand Up @@ -1060,25 +1070,32 @@ pub(crate) fn into_py(py: Python<'_>, expr: &AExpr) -> PyResult<PyObject> {
return Err(PyNotImplementedError::new_err("search sorted"))
},
FunctionExpr::Range(_) => return Err(PyNotImplementedError::new_err("range")),
FunctionExpr::Trigonometry(trigfun) => match trigfun {
TrigonometricFunction::Cos => ("cos",),
TrigonometricFunction::Cot => ("cot",),
TrigonometricFunction::Sin => ("sin",),
TrigonometricFunction::Tan => ("tan",),
TrigonometricFunction::ArcCos => ("arccos",),
TrigonometricFunction::ArcSin => ("arcsin",),
TrigonometricFunction::ArcTan => ("arctan",),
TrigonometricFunction::Cosh => ("cosh",),
TrigonometricFunction::Sinh => ("sinh",),
TrigonometricFunction::Tanh => ("tanh",),
TrigonometricFunction::ArcCosh => ("arccosh",),
TrigonometricFunction::ArcSinh => ("arcsinh",),
TrigonometricFunction::ArcTanh => ("arctanh",),
TrigonometricFunction::Degrees => ("degrees",),
TrigonometricFunction::Radians => ("radians",),
}
.to_object(py),
#[cfg(feature = "trigonometry")]
FunctionExpr::Trigonometry(trigfun) => {
use polars_plan::dsl::function_expr::trigonometry::TrigonometricFunction;

match trigfun {
TrigonometricFunction::Cos => ("cos",),
TrigonometricFunction::Cot => ("cot",),
TrigonometricFunction::Sin => ("sin",),
TrigonometricFunction::Tan => ("tan",),
TrigonometricFunction::ArcCos => ("arccos",),
TrigonometricFunction::ArcSin => ("arcsin",),
TrigonometricFunction::ArcTan => ("arctan",),
TrigonometricFunction::Cosh => ("cosh",),
TrigonometricFunction::Sinh => ("sinh",),
TrigonometricFunction::Tanh => ("tanh",),
TrigonometricFunction::ArcCosh => ("arccosh",),
TrigonometricFunction::ArcSinh => ("arcsinh",),
TrigonometricFunction::ArcTanh => ("arctanh",),
TrigonometricFunction::Degrees => ("degrees",),
TrigonometricFunction::Radians => ("radians",),
}
.to_object(py)
},
#[cfg(feature = "trigonometry")]
FunctionExpr::Atan2 => ("atan2",).to_object(py),
#[cfg(feature = "sign")]
FunctionExpr::Sign => ("sign",).to_object(py),
FunctionExpr::FillNull => ("fill_null",).to_object(py),
FunctionExpr::RollingExpr(rolling) => match rolling {
Expand Down
1 change: 0 additions & 1 deletion py-polars/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(vec_into_raw_parts)]
#![allow(clippy::nonstandard_macro_braces)] // Needed because clippy does not understand proc macro of PyO3
#![allow(clippy::transmute_undefined_repr)]
#![allow(non_local_definitions)]
Expand Down

0 comments on commit d1e0f63

Please sign in to comment.