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!: feature flags reorganizization #800

Merged
merged 5 commits into from
Feb 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
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

### Other breaking changes

- The `simd` feature of the Rust library is removed in favor of
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you add details on whether it changes something for the users? Should they change anything?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since we can update the NEWS file later, could you approve it for now?

It contains changes to the manifest file, and given the caching and the number of jobs triggered, I don't want to prolong this PR with only a documentation update.

the new `nightly` feature (#800).
- The following functions were deprecated in 0.13.0 and are now removed (#783):
- `$list$lengths()` -> `$list$len()`
- `pl$from_arrow()` -> `as_polars_df()` or `as_polars_series()`
Expand Down Expand Up @@ -51,6 +53,10 @@
- `pl$threadpool_size()` is deprecated and will be removed in 0.15.0. Use
`pl$thread_pool_size()` instead (#784).

### Other improvements

- The `sql` feature is included in the default feature (#800).
Copy link
Collaborator

Choose a reason for hiding this comment

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

same


## Polars R Package 0.13.1

### New features
Expand Down
16 changes: 6 additions & 10 deletions R/expr__array.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,16 @@ ExprArr_sum = function() .pr$Expr$arr_sum(self)
#' Find the maximum value in an array
#'
#' @return Expr
#' @details
#' This method is only available with the "simd" feature.
#' See [polars_info] for more details.
#' @inherit ExprStr_to_titlecase details
#' @aliases arr_max
#' @examplesIf polars_info()$features$simd
#' @examplesIf polars_info()$features$nightly
#' df = pl$DataFrame(
#' values = list(c(1, 2), c(3, 4), c(5, 6)),
#' schema = list(values = pl$Array(pl$Float64, 2))
#' )
#' df$with_columns(max = pl$col("values")$arr$max())
ExprArr_max = function() {
# TODO: not to check simd here
check_feature("simd", "in $arr$max():")
check_feature("nightly", "in $arr$max():")

.pr$Expr$arr_max(self)
}
Expand All @@ -38,18 +35,17 @@ ExprArr_max = function() {

#' Find the minimum value in an array
#'
#' @inherit ExprArr_max details
#' @inherit ExprStr_to_titlecase details
#' @return Expr
#' @aliases arr_min
#' @examplesIf polars_info()$features$simd
#' @examplesIf polars_info()$features$nightly
#' df = pl$DataFrame(
#' values = list(c(1, 2), c(3, 4), c(5, 6)),
#' schema = list(values = pl$Array(pl$Float64, 2))
#' )
#' df$with_columns(min = pl$col("values")$arr$min())
ExprArr_min = function() {
# TODO: not to check simd here
check_feature("simd", "in $arr$min():")
check_feature("nightly", "in $arr$min():")

.pr$Expr$arr_min(self)
}
Expand Down
8 changes: 4 additions & 4 deletions R/expr__string.R
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,12 @@ ExprStr_to_lowercase = function() {
#' @keywords ExprStr
#' @return Expr of String titlecase chars
#' @details
#' This method is only available with the "simd" feature.
#' See [polars_info] for more details.
#' @examplesIf polars_info()$features$simd
#' This method is only available with the "nightly" feature.
#' See [polars_info()] for more details.
#' @examplesIf polars_info()$features$nightly
#' pl$lit(c("hello there", "HI, THERE", NA))$str$to_titlecase()$to_series()
ExprStr_to_titlecase = function() {
check_feature("simd", "in $to_titlecase():")
check_feature("nightly", "in $to_titlecase():")

.pr$Expr$str_to_titlecase(self) |>
unwrap("in $to_titlecase():")
Expand Down
4 changes: 2 additions & 2 deletions R/polars_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#'
#' polars_info()$rust_polars
#'
#' polars_info()$features$simd
#' polars_info()$features$nightly
polars_info = function() {
# Similar to arrow::arrow_info()
out = list(
Expand Down Expand Up @@ -58,7 +58,7 @@ print.polars_info = function(x, ...) {
#' @return TRUE invisibly if the feature is enabled
#' @examples
#' tryCatch(
#' check_feature("simd", "in example"),
#' check_feature("nightly", "in example"),
#' error = \(e) cat(as.character(e))
#' )
#' tryCatch(
Expand Down
6 changes: 3 additions & 3 deletions man/ExprArr_max.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/ExprArr_min.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/ExprStr_to_titlecase.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/polars_info.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions src/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ publish = false
crate-type = ['staticlib']

[features]
default = []
full_features = ["simd", "sql", "disable_limit_max_threads"]
default = ["sql"]
full_features = ["default", "nightly", "disable_limit_max_threads"]
disable_limit_max_threads = []
simd = ["polars/simd"]
sql = ["polars/sql"]
# also includes simd, requires nightly
nightly = ["polars/nightly"]

rpolars_debug_print = []

[workspace]
Expand Down
5 changes: 2 additions & 3 deletions src/rust/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ use polars;
fn cargo_rpolars_feature_info() -> List {
list!(
default = cfg!(feature = "default"),
// `full_features` is a combination of `simd` and `sql` features
full_features = cfg!(feature = "simd")
full_features = cfg!(feature = "nightly")
& cfg!(feature = "sql")
& cfg!(feature = "disable_limit_max_threads"),
disable_limit_max_threads = cfg!(feature = "disable_limit_max_threads"),
simd = cfg!(feature = "simd"),
nightly = cfg!(feature = "nightly"),
sql = cfg!(feature = "sql"),
rpolars_debug_print = cfg!(feature = "rpolars_debug_print"),
)
Expand Down
8 changes: 4 additions & 4 deletions src/rust/src/lazy/dsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2573,16 +2573,16 @@ impl RPolarsExpr {
}
}

// handle varition in implementation if not simd
// handle varition in implementation if not the nightly feature
// could not get cfg feature flags conditions to work inside extendr macro
// Therefore place it outside here instead
#[allow(unused)]
fn f_str_to_titlecase(expr: &RPolarsExpr) -> RResult<RPolarsExpr> {
#[cfg(feature = "simd")]
#[cfg(feature = "nightly")]
return (Ok(expr.0.clone().str().to_titlecase().into()));

#[cfg(not(feature = "simd"))]
rerr().plain("$to_titlecase() is only available with the 'simd' feature")
#[cfg(not(feature = "nightly"))]
rerr().plain("$to_titlecase() is only available with the 'nightly' feature")
}

//allow proto expression that yet only are strings
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/polars_info.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
default FALSE
full_features FALSE
disable_limit_max_threads FALSE
simd FALSE
nightly FALSE
sql FALSE
rpolars_debug_print FALSE

Expand Down
8 changes: 3 additions & 5 deletions tests/testthat/test-expr_array.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ test_that("arr$sum", {
})

test_that("arr$max and arr$min", {
# TODO: not to check simd here
skip_if_not(polars_info()$features$simd)
skip_if_not(polars_info()$features$nightly)

df = pl$DataFrame(
ints = list(1:2, c(1L, NA_integer_), c(NA_integer_, NA_integer_)),
Expand Down Expand Up @@ -50,9 +49,8 @@ test_that("arr$max and arr$min", {
)
})

test_that("arr$max and arr$min error if the simd feature is false", {
# TODO: not to check simd here
skip_if(polars_info()$features$simd)
test_that("arr$max and arr$min error if the nightly feature is false", {
skip_if(polars_info()$features$nightly)

df = pl$DataFrame(
ints = list(1:2, c(1L, NA_integer_), c(NA_integer_, NA_integer_)),
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-expr_string.R
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,17 @@ test_that("to_uppercase, to_lowercase", {
)
})

test_that("to_titlecase - enabled via the simd feature", {
skip_if_not(polars_info()$features$simd)
test_that("to_titlecase - enabled via the nightly feature", {
skip_if_not(polars_info()$features$nightly)
df2 = pl$DataFrame(foo = c("hi there", "HI, THERE", NA))
expect_identical(
df2$select(pl$col("foo")$str$to_titlecase())$to_list()$foo,
c("Hi There", "Hi, There", NA)
)
})

test_that("to_titlecase - enabled via the simd feature", {
skip_if(polars_info()$features$simd)
test_that("to_titlecase - enabled via the nightly feature", {
skip_if(polars_info()$features$nightly)
expect_error(pl$col("foo")$str$to_titlecase())
})

Expand Down
5 changes: 3 additions & 2 deletions vignettes/install.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,14 @@ For example, to enable the `full_features` feature, set the environment variable

Currently `full_features` would work as a combination of the following features.

- The `default` feature
- `sql` for enable `pl$SQLContext()`.
- Features for CRAN compatibility
- `disable_limit_max_threads`, this feature disables the automatic limit of the maximum number of threads to 2 for CRAN compatibility,
and the maximum number of threads is used by default.
See `?pl_thread_pool_size` for details.
- Features for nightly toolchain
- `simd` for SIMD support.
- `sql` for enable `pl$SQLContext()`.
- `nightly` for nightly toolchain features and SIMD.

Note that nightly features requires the Rust nightly toolchain `r rust_toolchain_version`.

Expand Down
Loading