Skip to content

Commit

Permalink
fix tests and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
eitsupi committed Nov 3, 2024
1 parent 9b7be4b commit e257725
Show file tree
Hide file tree
Showing 30 changed files with 143 additions and 147 deletions.
2 changes: 1 addition & 1 deletion R/after-wrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ pub_class_env = as.environment(mget(pl_class_names, envir = pub_env))

#' Select from an empty DataFrame
#'
#' `pl$select(...)` is a shorthand for `as_polars_df(list())$select(...)`
#' `pl$select(...)` is a shorthand for `pl$DataFrame(list())$select(...)`
#' @keywords DataFrame
#' @param ... [Expressions][Expr_class]
#' @return a [DataFrame][DataFrame_class]
Expand Down
10 changes: 5 additions & 5 deletions R/dataframe__frame.R
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ DataFrame_drop = function(..., strict = TRUE) {
#' tmp = mtcars
#' tmp[1:3, "mpg"] = NA
#' tmp[4, "hp"] = NA
#' tmp = pl$DataFrame(tmp)
#' tmp = as_polars_df(tmp)
#'
#' # number of rows in `tmp` before dropping nulls
#' tmp$height
Expand Down Expand Up @@ -1045,8 +1045,8 @@ DataFrame_to_list = function(unnest_structs = TRUE, ..., int64_conversion = pola
#' @keywords DataFrame
#' @examples
#' # inner join by default
#' df1 = as_polars_df(list(key = 1:3, payload = c("f", "i", NA)))
#' df2 = as_polars_df(list(key = c(3L, 4L, 5L, NA_integer_)))
#' df1 = pl$DataFrame(list(key = 1:3, payload = c("f", "i", NA)))
#' df2 = pl$DataFrame(list(key = c(3L, 4L, 5L, NA_integer_)))
#' df1$join(other = df2, on = "key")
#'
#' # cross join
Expand Down Expand Up @@ -2073,7 +2073,7 @@ DataFrame_write_parquet = function(
#'
#' @examples
#' if (require("jsonlite", quiet = TRUE)) {
#' dat = pl$DataFrame(head(mtcars))
#' dat = as_polars_df(head(mtcars))
#' destination = tempfile()
#'
#' dat$select(pl$col("drat", "mpg"))$write_json(destination)
Expand Down Expand Up @@ -2101,7 +2101,7 @@ DataFrame_write_json = function(
#' @rdname IO_write_ndjson
#'
#' @examples
#' dat = pl$DataFrame(head(mtcars))
#' dat = as_polars_df(head(mtcars))
#'
#' destination = tempfile()
#' dat$select(pl$col("drat", "mpg"))$write_ndjson(destination)
Expand Down
48 changes: 24 additions & 24 deletions R/expr__expr.R
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ Expr_gt_eq = function(other) {
#' context only.
#' @return Expr
#' @examples
#' df = as_polars_df(list(
#' df = pl$DataFrame(list(
#' group = c("one", "one", "one", "two", "two", "two"),
#' value = c(94, 95, 96, 97, 97, 99)
#' ))
Expand Down Expand Up @@ -639,7 +639,7 @@ Expr_len = use_extendr_wrapper
#' `drop_nans()`
#' @return Expr
#' @examples
#' as_polars_df(list(x = c(1, 2, NaN, NA)))$select(pl$col("x")$drop_nulls())
#' pl$DataFrame(list(x = c(1, 2, NaN, NA)))$select(pl$col("x")$drop_nulls())
Expr_drop_nulls = use_extendr_wrapper

#' Drop NaN
Expand All @@ -653,15 +653,15 @@ Expr_drop_nulls = use_extendr_wrapper
#'
#' @return Expr
#' @examples
#' as_polars_df(list(x = c(1, 2, NaN, NA)))$select(pl$col("x")$drop_nans())
#' pl$DataFrame(list(x = c(1, 2, NaN, NA)))$select(pl$col("x")$drop_nans())
Expr_drop_nans = use_extendr_wrapper

#' Check if elements are NULL
#'
#' Returns a boolean Series indicating which values are null.
#' @return Expr
#' @examples
#' as_polars_df(list(x = c(1, NA, 3)))$select(pl$col("x")$is_null())
#' pl$DataFrame(list(x = c(1, NA, 3)))$select(pl$col("x")$is_null())
Expr_is_null = use_extendr_wrapper

#' Check if elements are not NULL
Expand All @@ -670,7 +670,7 @@ Expr_is_null = use_extendr_wrapper
#' for `$is_null()$not()`.
#' @return Expr
#' @examples
#' as_polars_df(list(x = c(1, NA, 3)))$select(pl$col("x")$is_not_null())
#' pl$DataFrame(list(x = c(1, NA, 3)))$select(pl$col("x")$is_not_null())
Expr_is_not_null = use_extendr_wrapper


Expand Down Expand Up @@ -844,7 +844,7 @@ Expr_map_batches = function(f, output_type = NULL, agg_list = FALSE, in_backgrou
#' # First we multiply each element of a Series of 1M elements by 2.
#' n = 1000000L
#' set.seed(1)
#' df = as_polars_df(list(
#' df = pl$DataFrame(list(
#' a = 1:n,
#' b = sample(letters, n, replace = TRUE)
#' ))
Expand Down Expand Up @@ -926,7 +926,7 @@ Expr_map_elements = function(f, return_type = NULL, strict_return_type = TRUE, a
#' @return Expr
#' @name Expr_reverse
#' @examples
#' as_polars_df(list(a = 1:5))$select(pl$col("a")$reverse())
#' pl$DataFrame(list(a = 1:5))$select(pl$col("a")$reverse())
Expr_reverse = function() {
.pr$Expr$reverse(self)
}
Expand Down Expand Up @@ -1103,7 +1103,7 @@ Expr_exclude = function(columns) {
#' Returns a boolean Series indicating which values are finite.
#' @return Expr
#' @examples
#' as_polars_df(list(alice = c(0, NaN, NA, Inf, -Inf)))$
#' pl$DataFrame(list(alice = c(0, NaN, NA, Inf, -Inf)))$
#' with_columns(finite = pl$col("alice")$is_finite())
Expr_is_finite = use_extendr_wrapper

Expand All @@ -1116,7 +1116,7 @@ Expr_is_finite = use_extendr_wrapper
#' @name Expr_is_infinite
#' @format NULL
#' @examples
#' as_polars_df(list(alice = c(0, NaN, NA, Inf, -Inf)))$
#' pl$DataFrame(list(alice = c(0, NaN, NA, Inf, -Inf)))$
#' with_columns(infinite = pl$col("alice")$is_infinite())
Expr_is_infinite = use_extendr_wrapper

Expand All @@ -1130,7 +1130,7 @@ Expr_is_infinite = use_extendr_wrapper
#'
#' @format NULL
#' @examples
#' as_polars_df(list(alice = c(0, NaN, NA, Inf, -Inf)))$
#' pl$DataFrame(list(alice = c(0, NaN, NA, Inf, -Inf)))$
#' with_columns(nan = pl$col("alice")$is_nan())
Expr_is_nan = use_extendr_wrapper

Expand All @@ -1144,7 +1144,7 @@ Expr_is_nan = use_extendr_wrapper
#' @name Expr_is_not_nan
#' @format NULL
#' @examples
#' as_polars_df(list(alice = c(0, NaN, NA, Inf, -Inf)))$
#' pl$DataFrame(list(alice = c(0, NaN, NA, Inf, -Inf)))$
#' with_columns(not_nan = pl$col("alice")$is_not_nan())
Expr_is_not_nan = use_extendr_wrapper

Expand All @@ -1162,16 +1162,16 @@ Expr_is_not_nan = use_extendr_wrapper
#' @return Expr
#' @examples
#' # as head
#' as_polars_df(list(a = 0:100))$select(
#' pl$DataFrame(list(a = 0:100))$select(
#' pl$all()$slice(0, 6)
#' )
#'
#' # as tail
#' as_polars_df(list(a = 0:100))$select(
#' pl$DataFrame(list(a = 0:100))$select(
#' pl$all()$slice(-6, 6)
#' )
#'
#' as_polars_df(list(a = 0:100))$select(
#' pl$DataFrame(list(a = 0:100))$select(
#' pl$all()$slice(80)
#' )
#'
Expand All @@ -1194,13 +1194,13 @@ Expr_slice = function(offset, length = NULL) {
#' @name Expr_append
#' @examples
#' # append bottom to to row
#' df = as_polars_df(list(a = 1:3, b = c(NA_real_, 4, 5)))
#' df = pl$DataFrame(list(a = 1:3, b = c(NA_real_, 4, 5)))
#' df$select(pl$all()$head(1)$append(pl$all()$tail(1)))
#'
#' # implicit upcast, when default = TRUE
#' as_polars_df(list())$select(pl$lit(42)$append(42L))
#' as_polars_df(list())$select(pl$lit(42)$append(FALSE))
#' as_polars_df(list())$select(pl$lit("Bob")$append(FALSE))
#' pl$DataFrame(list())$select(pl$lit(42)$append(42L))
#' pl$DataFrame(list())$select(pl$lit(42)$append(FALSE))
#' pl$DataFrame(list())$select(pl$lit("Bob")$append(FALSE))
Expr_append = function(other, upcast = TRUE) {
.pr$Expr$append(self, wrap_e(other), upcast)
}
Expand All @@ -1215,7 +1215,7 @@ Expr_append = function(other, upcast = TRUE) {
#' See rechunk() explained here \code{\link[polars]{docs_translations}}.
#' @examples
#' # get chunked lengths with/without rechunk
#' series_list = as_polars_df(list(a = 1:3, b = 4:6))$select(
#' series_list = pl$DataFrame(list(a = 1:3, b = 4:6))$select(
#' pl$col("a")$append(pl$col("b"))$alias("a_chunked"),
#' pl$col("a")$append(pl$col("b"))$rechunk()$alias("a_rechunked")
#' )$get_columns()
Expand Down Expand Up @@ -1907,7 +1907,7 @@ Expr_over = function(..., order_by = NULL, mapping_strategy = "group_to_rows") {
#' @return Expr
#'
#' @examples
#' pl$DataFrame(head(mtcars[, 1:2]))$
#' as_polars_df(head(mtcars[, 1:2]))$
#' with_columns(is_unique = pl$col("mpg")$is_unique())
Expr_is_unique = use_extendr_wrapper

Expand All @@ -1916,7 +1916,7 @@ Expr_is_unique = use_extendr_wrapper
#' @return Expr
#'
#' @examples
#' pl$DataFrame(head(mtcars[, 1:2]))$
#' as_polars_df(head(mtcars[, 1:2]))$
#' with_columns(is_ufirst = pl$col("mpg")$is_first_distinct())
Expr_is_first_distinct = use_extendr_wrapper

Expand All @@ -1925,7 +1925,7 @@ Expr_is_first_distinct = use_extendr_wrapper
#' @return Expr
#'
#' @examples
#' pl$DataFrame(head(mtcars[, 1:2]))$
#' as_polars_df(head(mtcars[, 1:2]))$
#' with_columns(is_ulast = pl$col("mpg")$is_last_distinct())
Expr_is_last_distinct = use_extendr_wrapper

Expand All @@ -1936,7 +1936,7 @@ Expr_is_last_distinct = use_extendr_wrapper
#' @return Expr
#'
#' @examples
#' pl$DataFrame(head(mtcars[, 1:2]))$
#' as_polars_df(head(mtcars[, 1:2]))$
#' with_columns(is_duplicated = pl$col("mpg")$is_duplicated())
Expr_is_duplicated = use_extendr_wrapper

Expand Down Expand Up @@ -2831,7 +2831,7 @@ Expr_pct_change = function(n = 1) {
#' @return Expr
#' @inherit Expr_rolling_skew details
#' @examples
#' df = as_polars_df(list(a = c(1:3, 2:1)))
#' df = pl$DataFrame(list(a = c(1:3, 2:1)))
#' df$select(pl$col("a")$skew())
Expr_skew = function(bias = TRUE) {
.pr$Expr$skew(self, bias)
Expand Down
14 changes: 7 additions & 7 deletions R/expr__list.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' @return Expr
#'
#' @examples
#' df = as_polars_df(list(list_of_strs = list(c("a", "b", NA), "c")))
#' df = pl$DataFrame(list(list_of_strs = list(c("a", "b", NA), "c")))
#' df$with_columns(len_list = pl$col("list_of_strs")$list$len())
ExprList_len = function() .pr$Expr$list_len(self)

Expand Down Expand Up @@ -200,7 +200,7 @@ ExprList_gather_every = function(n, offset = 0) {
#' @return Expr
#'
#' @examples
#' df = as_polars_df(list(a = list(3:1, NULL, 1:2)))
#' df = pl$DataFrame(list(a = list(3:1, NULL, 1:2)))
#' df$with_columns(
#' first = pl$col("a")$list$first()
#' )
Expand All @@ -214,7 +214,7 @@ ExprList_first = function() {
#' @return Expr
#'
#' @examples
#' df = as_polars_df(list(a = list(3:1, NULL, 1:2)))
#' df = pl$DataFrame(list(a = list(3:1, NULL, 1:2)))
#' df$with_columns(
#' last = pl$col("a")$list$last()
#' )
Expand Down Expand Up @@ -272,7 +272,7 @@ ExprList_join = function(separator, ignore_nulls = FALSE) {
#' @return Expr
#'
#' @examples
#' df = as_polars_df(list(s = list(1:2, 2:1)))
#' df = pl$DataFrame(list(s = list(1:2, 2:1)))
#' df$with_columns(
#' arg_min = pl$col("s")$list$arg_min()
#' )
Expand All @@ -283,7 +283,7 @@ ExprList_arg_min = function() .pr$Expr$list_arg_min(self)
#' @return Expr
#'
#' @examples
#' df = as_polars_df(list(s = list(1:2, 2:1)))
#' df = pl$DataFrame(list(s = list(1:2, 2:1)))
#' df$with_columns(
#' arg_max = pl$col("s")$list$arg_max()
#' )
Expand All @@ -304,7 +304,7 @@ ExprList_arg_max = function() .pr$Expr$list_arg_max(self)
#' @return Expr
#'
#' @examples
#' df = as_polars_df(list(s = list(1:4, c(10L, 2L, 1L))))
#' df = pl$DataFrame(list(s = list(1:4, c(10L, 2L, 1L))))
#' df$with_columns(diff = pl$col("s")$list$diff(2))
#'
#' # negative value starts shifting from the end
Expand Down Expand Up @@ -430,7 +430,7 @@ ExprList_tail = function(n = 5L) {
#' @return Expr
#'
#' @examples
#' df = as_polars_df(list(a = list(1:2, 1:3)))
#' df = pl$DataFrame(list(a = list(1:2, 1:3)))
#'
#' # this discards the third value of the second list as the struct length is
#' # determined based on the length of the first non-empty list
Expand Down
2 changes: 1 addition & 1 deletion R/expr__name.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ExprName_prefix = function(prefix) {
#' @return Expr
#'
#' @examples
#' as_polars_df(list(alice = 1:3))$select(pl$col("alice")$alias("bob")$name$keep())
#' pl$DataFrame(list(alice = 1:3))$select(pl$col("alice")$alias("bob")$name$keep())
ExprName_keep = function() {
.pr$Expr$name_keep(self) |>
unwrap("in $name$keep():")
Expand Down
6 changes: 3 additions & 3 deletions R/lazyframe__lazy.R
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ LazyFrame_width = method_as_active_binding(\() length(self$schema))
#' ) # directly from vectors
#'
#' # from a list of vectors or data.frame
#' as_polars_lf(list(
#' pl$LazyFrame(list(
#' a = c(1, 2, 3, 4, 5),
#' b = 1:5,
#' c = letters[1:5],
Expand Down Expand Up @@ -1305,8 +1305,8 @@ LazyFrame_group_by = function(..., maintain_order = polars_options()$maintain_or
#' @return LazyFrame
#' @examples
#' # inner join by default
#' df1 = as_polars_lf(list(key = 1:3, payload = c("f", "i", NA)))
#' df2 = as_polars_lf(list(key = c(3L, 4L, 5L, NA_integer_)))
#' df1 = pl$LazyFrame(list(key = 1:3, payload = c("f", "i", NA)))
#' df2 = pl$LazyFrame(list(key = c(3L, 4L, 5L, NA_integer_)))
#' df1$join(other = df2, on = "key")
#'
#' # cross join
Expand Down
4 changes: 2 additions & 2 deletions R/polars_options.R
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ pl_using_string_cache = function() {
#' @examples
#' # activate string cache temporarily when constructing two DataFrame's
#' pl$with_string_cache({
#' df1 = pl$DataFrame(head(iris, 2))
#' df2 = pl$DataFrame(tail(iris, 2))
#' df1 = as_polars_df(head(iris, 2))
#' df2 = as_polars_df(tail(iris, 2))
#' })
#' pl$concat(list(df1, df2))
pl_with_string_cache = function(expr) {
Expand Down
2 changes: 1 addition & 1 deletion man/DataFrame_drop_nulls.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/Expr_is_duplicated.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/Expr_is_first_distinct.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/Expr_is_last_distinct.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/Expr_is_unique.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/IO_write_json.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/IO_write_ndjson.Rd

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

Loading

0 comments on commit e257725

Please sign in to comment.