Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(rust): Make no-default-features compile #17516

Merged
merged 1 commit into from
Jul 11, 2024
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 crates/polars-plan/src/dsl/function_expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ pub enum FunctionExpr {
SetSortedFlag(IsSorted),
#[cfg(feature = "ffi_plugin")]
/// Creating this node is unsafe
/// This will lead to calls over FFI>
/// This will lead to calls over FFI.
FfiPlugin {
/// Shared library.
lib: Arc<str>,
Expand Down
10 changes: 5 additions & 5 deletions docs/src/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ workspace = true
[[bin]]
name = "home"
path = "home/example.rs"
required-features = ["polars/lazy"]
required-features = ["polars/lazy", "polars/csv"]

[[bin]]
name = "user-guide-getting-started-expressions"
Expand Down Expand Up @@ -51,11 +51,11 @@ required-features = ["polars/lazy"]
[[bin]]
name = "user-guide-concepts-lazy-vs-eager"
path = "user-guide/concepts/lazy-vs-eager.rs"
required-features = ["polars/lazy"]
required-features = ["polars/lazy", "polars/csv"]
[[bin]]
name = "user-guide-concepts-streaming"
path = "user-guide/concepts/streaming.rs"
required-features = ["polars/lazy"]
required-features = ["polars/lazy", "polars/csv"]

[[bin]]
name = "user-guide-expressions-aggregation"
Expand Down Expand Up @@ -130,14 +130,14 @@ required-features = ["polars/lazy"]
[[bin]]
name = "user-guide-transformations-joins"
path = "user-guide/transformations/joins.rs"
required-features = ["polars/lazy"]
required-features = ["polars/lazy", "polars/asof_join"]
[[bin]]
name = "user-guide-transformations-unpivot"
path = "user-guide/transformations/unpivot.rs"
[[bin]]
name = "user-guide-transformations-pivot"
path = "user-guide/transformations/pivot.rs"
required-features = ["polars/lazy"]
required-features = ["polars/lazy", "polars/pivot"]

[[bin]]
name = "user-guide-transformations-time-series-filter"
Expand Down
2 changes: 2 additions & 0 deletions py-polars/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ workspace = true
features = [
"abs",
"approx_unique",
"array_any_all",
"arg_where",
"business",
"concat_str",
Expand All @@ -63,6 +64,7 @@ features = [
"ewma",
"ewma_by",
"fmt",
"fused",
"interpolate",
"interpolate_by",
"is_first_distinct",
Expand Down
4 changes: 3 additions & 1 deletion py-polars/src/conversion/any_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use std::borrow::Cow;

#[cfg(feature = "object")]
use polars::chunked_array::object::PolarsObjectSafe;
use polars::datatypes::{DataType, Field, OwnedObject, PlHashMap, TimeUnit};
#[cfg(feature = "object")]
use polars::datatypes::OwnedObject;
use polars::datatypes::{DataType, Field, PlHashMap, TimeUnit};
use polars::prelude::{AnyValue, Series};
use polars_core::export::chrono::{NaiveDate, NaiveDateTime, NaiveTime, TimeDelta, Timelike};
use polars_core::utils::any_values_to_supertype_and_n_dtypes;
Expand Down
2 changes: 2 additions & 0 deletions py-polars/src/conversion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use polars_core::utils::arrow::array::Array;
use polars_core::utils::arrow::types::NativeType;
use polars_core::utils::materialize_dyn_int;
use polars_lazy::prelude::*;
#[cfg(feature = "parquet")]
use polars_parquet::write::StatisticsOptions;
use polars_utils::total_ord::{TotalEq, TotalHash};
use pyo3::basic::CompareOp;
Expand Down Expand Up @@ -466,6 +467,7 @@ impl ToPyObject for Wrap<TimeUnit> {
}
}

#[cfg(feature = "parquet")]
impl<'s> FromPyObject<'s> for Wrap<StatisticsOptions> {
fn extract_bound(ob: &Bound<'s, PyAny>) -> PyResult<Self> {
let mut statistics = StatisticsOptions::empty();
Expand Down
1 change: 1 addition & 0 deletions py-polars/src/expr/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ impl PyExpr {
self.inner.clone().struct_().rename_fields(names).into()
}

#[cfg(feature = "json")]
fn struct_json_encode(&self) -> Self {
self.inner.clone().struct_().json_encode().into()
}
Expand Down
19 changes: 19 additions & 0 deletions py-polars/src/lazyframe/visitor/expr_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@ pub(crate) fn into_py(py: Python<'_>, expr: &AExpr) -> PyResult<PyObject> {
StringFunction::ExtractAll => {
(PyStringFunction::ExtractAll.into_py(py),).to_object(py)
},
#[cfg(feature = "extract_groups")]
StringFunction::ExtractGroups { dtype, pat } => (
PyStringFunction::ExtractGroups.into_py(py),
Wrap(dtype.clone()).to_object(py),
Expand All @@ -807,10 +808,12 @@ pub(crate) fn into_py(py: Python<'_>, expr: &AExpr) -> PyResult<PyObject> {
StringFunction::Lowercase => {
(PyStringFunction::Lowercase.into_py(py),).to_object(py)
},
#[cfg(feature = "extract_jsonpath")]
StringFunction::JsonDecode {
dtype: _,
infer_schema_len,
} => (PyStringFunction::JsonDecode.into_py(py), infer_schema_len).to_object(py),
#[cfg(feature = "extract_jsonpath")]
StringFunction::JsonPathMatch => {
(PyStringFunction::JsonPathMatch.into_py(py),).to_object(py)
},
Expand Down Expand Up @@ -881,20 +884,23 @@ pub(crate) fn into_py(py: Python<'_>, expr: &AExpr) -> PyResult<PyObject> {
(PyStringFunction::Uppercase.into_py(py),).to_object(py)
},
StringFunction::ZFill => (PyStringFunction::ZFill.into_py(py),).to_object(py),
#[cfg(feature = "find_many")]
StringFunction::ContainsMany {
ascii_case_insensitive,
} => (
PyStringFunction::ContainsMany.into_py(py),
ascii_case_insensitive,
)
.to_object(py),
#[cfg(feature = "find_many")]
StringFunction::ReplaceMany {
ascii_case_insensitive,
} => (
PyStringFunction::ReplaceMany.into_py(py),
ascii_case_insensitive,
)
.to_object(py),
#[cfg(feature = "find_many")]
StringFunction::ExtractMany { .. } => {
return Err(PyNotImplementedError::new_err("extract_many"))
},
Expand Down Expand Up @@ -1027,6 +1033,7 @@ pub(crate) fn into_py(py: Python<'_>, expr: &AExpr) -> PyResult<PyObject> {
BooleanFunction::Not => (PyBooleanFunction::Not,).into_py(py),
},
FunctionExpr::Abs => ("abs",).to_object(py),
#[cfg(feature = "hist")]
FunctionExpr::Hist { .. } => return Err(PyNotImplementedError::new_err("hist")),
FunctionExpr::NullCount => ("null_count",).to_object(py),
FunctionExpr::Pow(f) => match f {
Expand All @@ -1038,6 +1045,7 @@ pub(crate) fn into_py(py: Python<'_>, expr: &AExpr) -> PyResult<PyObject> {
return Err(PyNotImplementedError::new_err("hash"))
},
FunctionExpr::ArgWhere => ("argwhere",).to_object(py),
#[cfg(feature = "search_sorted")]
FunctionExpr::SearchSorted(_) => {
return Err(PyNotImplementedError::new_err("search sorted"))
},
Expand Down Expand Up @@ -1126,6 +1134,7 @@ pub(crate) fn into_py(py: Python<'_>, expr: &AExpr) -> PyResult<PyObject> {
FunctionExpr::Reshape(_, _) => {
return Err(PyNotImplementedError::new_err("reshape"))
},
#[cfg(feature = "repeat_by")]
FunctionExpr::RepeatBy => ("repeat_by",).to_object(py),
FunctionExpr::ArgUnique => ("argunique",).to_object(py),
FunctionExpr::Rank {
Expand All @@ -1137,6 +1146,7 @@ pub(crate) fn into_py(py: Python<'_>, expr: &AExpr) -> PyResult<PyObject> {
has_max: _,
} => return Err(PyNotImplementedError::new_err("clip")),
FunctionExpr::AsStruct => return Err(PyNotImplementedError::new_err("as struct")),
#[cfg(feature = "top_k")]
FunctionExpr::TopK { descending } => ("top_k", descending).to_object(py),
FunctionExpr::CumCount { reverse } => ("cumcount", reverse).to_object(py),
FunctionExpr::CumSum { reverse } => ("cumsum", reverse).to_object(py),
Expand All @@ -1159,6 +1169,7 @@ pub(crate) fn into_py(py: Python<'_>, expr: &AExpr) -> PyResult<PyObject> {
return Err(PyNotImplementedError::new_err("shrink type"))
},
FunctionExpr::Diff(_, _) => return Err(PyNotImplementedError::new_err("diff")),
#[cfg(feature = "pct_change")]
FunctionExpr::PctChange => {
return Err(PyNotImplementedError::new_err("pct change"))
},
Expand Down Expand Up @@ -1189,11 +1200,17 @@ pub(crate) fn into_py(py: Python<'_>, expr: &AExpr) -> PyResult<PyObject> {
FunctionExpr::Correlation { .. } => {
return Err(PyNotImplementedError::new_err("corr"))
},
#[cfg(feature = "peaks")]
FunctionExpr::PeakMin => return Err(PyNotImplementedError::new_err("peak min")),
#[cfg(feature = "peaks")]
FunctionExpr::PeakMax => return Err(PyNotImplementedError::new_err("peak max")),
#[cfg(feature = "cutqcut")]
FunctionExpr::Cut { .. } => return Err(PyNotImplementedError::new_err("cut")),
#[cfg(feature = "cutqcut")]
FunctionExpr::QCut { .. } => return Err(PyNotImplementedError::new_err("qcut")),
#[cfg(feature = "rle")]
FunctionExpr::RLE => return Err(PyNotImplementedError::new_err("rle")),
#[cfg(feature = "rle")]
FunctionExpr::RLEID => return Err(PyNotImplementedError::new_err("rleid")),
FunctionExpr::ToPhysical => {
return Err(PyNotImplementedError::new_err("to physical"))
Expand All @@ -1210,6 +1227,7 @@ pub(crate) fn into_py(py: Python<'_>, expr: &AExpr) -> PyResult<PyObject> {
},
)
.to_object(py),
#[cfg(feature = "ffi_plugin")]
FunctionExpr::FfiPlugin { .. } => {
return Err(PyNotImplementedError::new_err("ffi plugin"))
},
Expand Down Expand Up @@ -1260,6 +1278,7 @@ pub(crate) fn into_py(py: Python<'_>, expr: &AExpr) -> PyResult<PyObject> {
FunctionExpr::Business(_) => {
return Err(PyNotImplementedError::new_err("business"))
},
#[cfg(feature = "top_k")]
FunctionExpr::TopKBy { descending } => ("top_k_by", descending).to_object(py),
FunctionExpr::EwmMeanBy { half_life: _ } => {
return Err(PyNotImplementedError::new_err("ewm_mean_by"))
Expand Down
6 changes: 6 additions & 0 deletions py-polars/src/lazyframe/visitor/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ pub(crate) fn into_py(py: Python<'_>, plan: &IR) -> PyResult<PyObject> {
inner: file_options.clone(),
},
scan_type: match scan_type {
#[cfg(feature = "csv")]
FileScan::Csv {
options,
cloud_options,
Expand All @@ -328,6 +329,7 @@ pub(crate) fn into_py(py: Python<'_>, plan: &IR) -> PyResult<PyObject> {
.map_err(|err| PyValueError::new_err(format!("{err:?}")))?;
("csv", options, cloud_options).into_py(py)
},
#[cfg(feature = "parquet")]
Copy link
Collaborator

@wence- wence- Jul 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Does feature="parquet" imply feature="serde" such that serde_json is available?

(Thanks for this, btw!)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, it doesn't, there's still various issues if you only compile with --no-default-features --features parquet.

But that's for a future follow-up PR. I want to tackle this in bits.

FileScan::Parquet {
options,
cloud_options,
Expand All @@ -339,7 +341,9 @@ pub(crate) fn into_py(py: Python<'_>, plan: &IR) -> PyResult<PyObject> {
.map_err(|err| PyValueError::new_err(format!("{err:?}")))?;
("parquet", options, cloud_options).into_py(py)
},
#[cfg(feature = "ipc")]
FileScan::Ipc { .. } => return Err(PyNotImplementedError::new_err("ipc scan")),
#[cfg(feature = "json")]
FileScan::NDJson { options } => {
let options = serde_json::to_string(options)
.map_err(|err| PyValueError::new_err(format!("{err:?}")))?;
Expand Down Expand Up @@ -451,6 +455,7 @@ pub(crate) fn into_py(py: Python<'_>, plan: &IR) -> PyResult<PyObject> {
JoinType::Right => "right",
JoinType::Inner => "inner",
JoinType::Full => "full",
#[cfg(feature = "asof_join")]
JoinType::AsOf(_) => return Err(PyNotImplementedError::new_err("asof join")),
JoinType::Cross => "cross",
JoinType::Semi => "leftsemi",
Expand Down Expand Up @@ -533,6 +538,7 @@ pub(crate) fn into_py(py: Python<'_>, plan: &IR) -> PyResult<PyObject> {
)
.to_object(py),
FunctionNode::Rechunk => ("rechunk",).to_object(py),
#[cfg(feature = "merge_sorted")]
FunctionNode::MergeSorted { column } => {
("merge_sorted", column.to_string()).to_object(py)
},
Expand Down
1 change: 1 addition & 0 deletions py-polars/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ fn polars(py: Python, m: &Bound<PyModule>) -> PyResult<()> {
add_build_info(py, m)?;

// Plugins
#[cfg(feature = "ffi_plugin")]
m.add_wrapped(wrap_pyfunction!(functions::register_plugin_function))
.unwrap();

Expand Down