From 2a66f27f8e80f218690c6bc40865dd0c0b1b65e0 Mon Sep 17 00:00:00 2001 From: eitsupi <50911393+eitsupi@users.noreply.github.com> Date: Mon, 4 Nov 2024 21:09:29 +0900 Subject: [PATCH] fix!: warn for `pl$DataFrame()` (#1275) Co-authored-by: Etienne Bacher <52219252+etiennebacher@users.noreply.github.com> --- NEWS.md | 6 + R/after-wrappers.R | 6 +- R/dataframe__frame.R | 129 +++++++-------- R/datatype.R | 2 +- R/expr__expr.R | 36 ++--- R/expr__name.R | 4 +- R/functions__lazy.R | 14 +- R/group_by.R | 8 +- R/io_parquet.R | 8 +- R/lazyframe__group_by.R | 2 +- R/lazyframe__lazy.R | 80 +++++----- R/polars_options.R | 4 +- R/rbackground.R | 2 +- R/s3-methods.R | 4 +- R/sql.R | 4 +- altdoc/reference_home.Rmd | 2 +- man/DataFrame_clone.Rd | 4 +- man/DataFrame_describe.Rd | 2 +- man/DataFrame_drop.Rd | 4 +- man/DataFrame_drop_in_place.Rd | 2 +- man/DataFrame_drop_nulls.Rd | 2 +- man/DataFrame_dtype_strings.Rd | 2 +- man/DataFrame_equals.Rd | 6 +- man/DataFrame_estimated_size.Rd | 2 +- man/DataFrame_filter.Rd | 4 +- man/DataFrame_first.Rd | 2 +- man/DataFrame_get_column.Rd | 2 +- man/DataFrame_glimpse.Rd | 2 +- man/DataFrame_last.Rd | 2 +- man/DataFrame_lazy.Rd | 2 +- man/DataFrame_max.Rd | 2 +- man/DataFrame_mean.Rd | 2 +- man/DataFrame_median.Rd | 2 +- man/DataFrame_min.Rd | 2 +- man/DataFrame_quantile.Rd | 2 +- man/DataFrame_reverse.Rd | 2 +- man/DataFrame_sample.Rd | 2 +- man/DataFrame_select.Rd | 2 +- man/DataFrame_select_seq.Rd | 2 +- man/DataFrame_slice.Rd | 2 +- man/DataFrame_std.Rd | 2 +- man/DataFrame_sum.Rd | 2 +- man/DataFrame_to_data_frame.Rd | 2 +- man/DataFrame_to_list.Rd | 2 +- man/DataFrame_to_series.Rd | 2 +- man/DataFrame_transpose.Rd | 4 +- man/DataFrame_var.Rd | 2 +- man/DataFrame_with_columns.Rd | 6 +- man/DataFrame_with_columns_seq.Rd | 6 +- man/DataFrame_with_row_index.Rd | 2 +- man/ExprName_prefix.Rd | 2 +- man/ExprName_suffix.Rd | 2 +- man/Expr_approx_n_unique.Rd | 2 +- man/Expr_exclude.Rd | 2 +- man/Expr_hash.Rd | 2 +- man/Expr_is_duplicated.Rd | 2 +- man/Expr_is_first_distinct.Rd | 2 +- man/Expr_is_last_distinct.Rd | 2 +- man/Expr_is_unique.Rd | 2 +- man/Expr_map_batches.Rd | 2 +- man/Expr_map_elements.Rd | 10 +- man/Expr_n_unique.Rd | 2 +- man/Expr_slice.Rd | 2 +- man/Expr_unique.Rd | 2 +- man/Expr_unique_counts.Rd | 2 +- man/Expr_value_counts.Rd | 2 +- man/GroupBy_quantile.Rd | 2 +- man/GroupBy_shift.Rd | 2 +- man/GroupBy_ungroup.Rd | 2 +- man/IO_read_parquet.Rd | 4 +- man/IO_scan_parquet.Rd | 4 +- man/IO_sink_csv.Rd | 2 +- man/IO_sink_ipc.Rd | 2 +- man/IO_sink_ndjson.Rd | 2 +- man/IO_sink_parquet.Rd | 2 +- man/IO_write_csv.Rd | 2 +- man/IO_write_ipc.Rd | 2 +- man/IO_write_json.Rd | 2 +- man/IO_write_ndjson.Rd | 2 +- man/IO_write_parquet.Rd | 2 +- man/LazyFrame_clone.Rd | 4 +- man/LazyFrame_collect.Rd | 2 +- man/LazyFrame_collect_in_background.Rd | 2 +- man/LazyFrame_drop.Rd | 4 +- man/LazyFrame_explain.Rd | 2 +- man/LazyFrame_fetch.Rd | 4 +- man/LazyFrame_filter.Rd | 2 +- man/LazyFrame_first.Rd | 2 +- man/LazyFrame_last.Rd | 2 +- man/LazyFrame_max.Rd | 2 +- man/LazyFrame_mean.Rd | 2 +- man/LazyFrame_median.Rd | 2 +- man/LazyFrame_min.Rd | 2 +- man/LazyFrame_print.Rd | 2 +- man/LazyFrame_profile.Rd | 4 +- man/LazyFrame_quantile.Rd | 2 +- man/LazyFrame_reverse.Rd | 2 +- man/LazyFrame_select.Rd | 2 +- man/LazyFrame_select_seq.Rd | 2 +- man/LazyFrame_slice.Rd | 4 +- man/LazyFrame_std.Rd | 2 +- man/LazyFrame_sum.Rd | 2 +- man/LazyFrame_var.Rd | 2 +- man/LazyFrame_with_columns.Rd | 6 +- man/LazyFrame_with_columns_seq.Rd | 6 +- man/LazyFrame_with_row_index.Rd | 2 +- man/LazyGroupBy_ungroup.Rd | 2 +- man/RThreadHandle_class.Rd | 2 +- man/S3_extract.Rd | 2 +- man/S3_na.omit.Rd | 2 +- man/SQLContext_register_many.Rd | 4 +- man/pl_DataFrame.Rd | 20 +-- man/pl_corr.Rd | 2 +- man/pl_cov.Rd | 2 +- man/pl_fold.Rd | 2 +- man/pl_implode.Rd | 2 +- man/pl_is_schema.Rd | 2 +- man/pl_reduce.Rd | 2 +- man/pl_rolling_corr.Rd | 2 +- man/pl_rolling_cov.Rd | 2 +- man/pl_with_string_cache.Rd | 4 +- man/polars_class_object.Rd | 4 +- tests/testthat/_snaps/dataframe.md | 4 +- tests/testthat/_snaps/deparse/dataframe.md | 30 ++-- tests/testthat/_snaps/pkg-knitr.md | 8 +- tests/testthat/files/dataframe.Rmd | 2 +- tests/testthat/test-as_polars.R | 16 +- tests/testthat/test-concat.R | 10 +- tests/testthat/test-context.R | 2 +- tests/testthat/test-csv-read.R | 4 +- tests/testthat/test-csv-write.R | 4 +- tests/testthat/test-dataframe.R | 160 +++++++++---------- tests/testthat/test-enable_string_cache.R | 8 +- tests/testthat/test-expr_expr.R | 28 ++-- tests/testthat/test-groupby.R | 28 ++-- tests/testthat/test-ipc.R | 2 +- tests/testthat/test-json_write.R | 4 +- tests/testthat/test-lazy.R | 130 +++++++-------- tests/testthat/test-lazy_functions.R | 4 +- tests/testthat/test-lazy_profile.R | 6 +- tests/testthat/test-named_exprs.R | 6 +- tests/testthat/test-parquet.R | 22 +-- tests/testthat/test-rbackground.R | 2 +- tests/testthat/test-s3-methods.R | 16 +- tests/testthat/test-sink_stream.R | 8 +- tests/testthat/test-sql.R | 4 +- tests/testthat/test-user_guide.R | 2 +- tests/testthat/test-whenthen.R | 2 +- tests/testthat/test-without_library_polars.R | 6 +- 149 files changed, 545 insertions(+), 570 deletions(-) diff --git a/NEWS.md b/NEWS.md index 82aa04aa7..f0becff77 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,12 @@ - `$compare()` is removed. (#1272) +### Deprecations + +- Passing a single data.frame to `pl$DataFrame()` or `pl$LazyFrame()` to convert a + data.frame to a polars DataFrame or LazyFrame is deprecated and a warning will + be shown. Use `as_polars_df()` or `as_polars_lf()` instead (#1275). + ### Bug fixes - Maintain level order when converting Enums to factors (#1252, @andyquinterom). diff --git a/R/after-wrappers.R b/R/after-wrappers.R index 0887329eb..6860bb762 100644 --- a/R/after-wrappers.R +++ b/R/after-wrappers.R @@ -83,7 +83,7 @@ extendr_method_to_pure_functions = function(env, class_name = NULL) { #' @export #' @examples #' # .pr$DataFrame$print() is an external function where self is passed as arg -#' .pr$DataFrame$print(self = pl$DataFrame(iris)) +#' .pr$DataFrame$print(self = as_polars_df(iris)) #' #' # show all content of .pr #' .pr$print_env(.pr, ".pr the collection of private method calls to rust-polars") @@ -332,12 +332,12 @@ pl_mem_address = function(robj) { #' @return not applicable #' @examples #' # all a polars object is only made of: -#' some_polars_object = pl$DataFrame(iris) +#' some_polars_object = as_polars_df(iris) #' str(some_polars_object) # External Pointer tagged with a class attribute. #' #' # All state is stored on rust side. #' #' # The single exception from the rule is class "GroupBy", where objects also have #' # two private attributes "groupby_input" and "maintain_order". -#' str(pl$DataFrame(iris)$group_by("Species")) +#' str(as_polars_df(iris)$group_by("Species")) NULL diff --git a/R/dataframe__frame.R b/R/dataframe__frame.R index 9983a5d8a..adbd168a4 100644 --- a/R/dataframe__frame.R +++ b/R/dataframe__frame.R @@ -227,10 +227,8 @@ DataFrame_width = method_as_active_binding(\() .pr$DataFrame$shape(self)[2L]) #' Create a new polars DataFrame #' #' @param ... One of the following: -#' - a list of mixed vectors and Series of equal length #' - mixed vectors and/or Series of equal length -#' - a positional argument of a [data.frame] or a [DataFrame][DataFrame_class] -#' (not recommended use). In this case, the object will be passed to [as_polars_df()]. +#' - a list of mixed vectors and Series of equal length (Deprecated, please use [as_polars_df()] instead). #' #' Columns will be named as of named arguments or alternatively by names of #' Series or given a placeholder name. @@ -238,7 +236,7 @@ DataFrame_width = method_as_active_binding(\() .pr$DataFrame$shape(self)[2L]) #' @param make_names_unique If `TRUE` (default), any duplicated names will be #' prefixed a running number. #' @param schema A named list that will be used to convert a variable to a -#' specific DataType. See Examples. +#' specific DataType. Same as `schema_overrides` of [as_polars_df()]. #' @seealso #' - [as_polars_df()] #' @return [DataFrame][DataFrame_class] @@ -250,20 +248,6 @@ DataFrame_width = method_as_active_binding(\() .pr$DataFrame$shape(self)[2L]) #' c = letters[1:5], #' d = list(1:1, 1:2, 1:3, 1:4, 1:5) #' ) # directly from vectors -#' -#' # from a list of vectors -#' pl$DataFrame(list( -#' a = c(1, 2, 3, 4, 5), -#' b = 1:5, -#' c = letters[1:5], -#' d = list(1L, 1:2, 1:3, 1:4, 1:5) -#' )) -#' -#' # from a data.frame -#' pl$DataFrame(mtcars) -#' -#' # custom schema -#' pl$DataFrame(iris, schema = list(Sepal.Length = pl$Float32, Species = pl$String)) pl_DataFrame = function(..., make_names_unique = TRUE, schema = NULL) { uw = \(res) unwrap(res, "in $DataFrame():") @@ -275,6 +259,11 @@ pl_DataFrame = function(..., make_names_unique = TRUE, schema = NULL) { # pass to `as_polars_df()` if (length(largs) == 1L && is.null(names(largs)) && (inherits(largs[[1]], skip_classes))) { + warning( + "Passing a `data.frame` or `RPolarsDataFrame` to `pl$DataFrame()` is deprecated and will be removed in the future.", + " Use `as_polars_df()` instead." + ) + # TODO: schema v.s. schema_overrides out = as_polars_df(largs[[1]], make_names_unique = make_names_unique, schema_overrides = schema) |> result() |> @@ -355,7 +344,7 @@ pl_DataFrame = function(..., make_names_unique = TRUE, schema = NULL) { #' @return self #' @export #' -#' @examples pl$DataFrame(iris) +#' @examples as_polars_df(iris) print.RPolarsDataFrame = function(x, ...) { x$print() invisible(x) @@ -365,7 +354,7 @@ print.RPolarsDataFrame = function(x, ...) { #' @noRd #' @return self #' -#' @examples pl$DataFrame(iris) +#' @examples as_polars_df(iris) DataFrame_print = function() { .pr$DataFrame$print(self) invisible(self) @@ -394,7 +383,7 @@ DataFrame.property_setters = new.env(parent = emptyenv()) #' with(.pr$env, ls(DataFrame.property_setters)) #' #' # specific use case for one object property 'columns' (names) -#' df = pl$DataFrame(iris) +#' df = as_polars_df(iris) #' #' # get values #' df$columns @@ -442,7 +431,7 @@ DataFrame.property_setters = new.env(parent = emptyenv()) #' @return A new `DataFrame` object with a counter column in front #' @docType NULL #' @examples -#' df = pl$DataFrame(mtcars) +#' df = as_polars_df(mtcars) #' #' # by default, the index starts at 0 (to mimic the behavior of Python Polars) #' df$with_row_index("idx") @@ -468,10 +457,10 @@ DataFrame.property_setters$columns = function(self, names) { #' #' @return DataFrame #' @examples -#' pl$DataFrame(mtcars)$drop(c("mpg", "hp")) +#' as_polars_df(mtcars)$drop(c("mpg", "hp")) #' #' # equivalent -#' pl$DataFrame(mtcars)$drop("mpg", "hp") +#' as_polars_df(mtcars)$drop("mpg", "hp") DataFrame_drop = function(..., strict = TRUE) { self$lazy()$drop(..., strict = strict)$collect() } @@ -488,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 @@ -554,7 +543,7 @@ DataFrame_unique = function( #' @return A character vector with the data type of each column #' @keywords DataFrame #' @examples -#' pl$DataFrame(iris)$dtype_strings() +#' as_polars_df(iris)$dtype_strings() DataFrame_dtype_strings = use_extendr_wrapper @@ -568,7 +557,7 @@ DataFrame_dtype_strings = use_extendr_wrapper #' @aliases lazy #' @keywords DataFrame LazyFrame_new #' @examples -#' pl$DataFrame(iris)$lazy() +#' as_polars_df(iris)$lazy() DataFrame_lazy = use_extendr_wrapper #' Clone a DataFrame @@ -580,7 +569,7 @@ DataFrame_lazy = use_extendr_wrapper #' #' @return A DataFrame #' @examples -#' df1 = pl$DataFrame(iris) +#' df1 = as_polars_df(iris) #' #' # Make a function to take a DataFrame, add an attribute, and return a DataFrame #' give_attr = function(data) { @@ -598,7 +587,7 @@ DataFrame_lazy = use_extendr_wrapper #' attr(data, "created_on") = "2024-01-29" #' data #' } -#' df1 = pl$DataFrame(iris) +#' df1 = as_polars_df(iris) #' df2 = give_attr(df1) #' #' # now, the original DataFrame doesn't get this attribute @@ -635,7 +624,7 @@ DataFrame_get_columns = use_extendr_wrapper #' @aliases DataFrame_get_column #' @keywords DataFrame #' @examples -#' df = pl$DataFrame(iris[1:2, ]) +#' df = as_polars_df(iris[1:2, ]) #' df$get_column("Species") DataFrame_get_column = function(name) { unwrap(.pr$DataFrame$get_column(self, name), "in $get_column():") @@ -655,7 +644,7 @@ DataFrame_get_column = function(name) { #' @return Series or NULL #' @keywords DataFrame #' @examples -#' df = pl$DataFrame(iris[1:10, ]) +#' df = as_polars_df(iris[1:10, ]) #' #' # default is to extract the first column #' df$to_series() @@ -714,7 +703,7 @@ DataFrame_sort = function( #' @return DataFrame #' @keywords DataFrame #' @examples -#' pl$DataFrame(iris)$select( +#' as_polars_df(iris)$select( #' pl$col("Sepal.Length")$abs()$alias("abs_SL"), #' (pl$col("Sepal.Length") + 2)$alias("add_2_SL") #' ) @@ -734,7 +723,7 @@ DataFrame_select = function(...) { #' preferred. #' #' @examples -#' pl$DataFrame(iris)$select_seq( +#' as_polars_df(iris)$select_seq( #' pl$col("Sepal.Length")$abs()$alias("abs_SL"), #' (pl$col("Sepal.Length") + 2)$alias("add_2_SL") #' ) @@ -751,7 +740,7 @@ DataFrame_select_seq = function(...) { #' @return Series #' @keywords DataFrame #' @examples -#' dat = pl$DataFrame(iris) +#' dat = as_polars_df(iris) #' x = dat$drop_in_place("Species") #' x #' dat$columns @@ -767,9 +756,9 @@ DataFrame_drop_in_place = function(name) { #' @return A logical value #' @keywords DataFrame #' @examples -#' dat1 = pl$DataFrame(iris) -#' dat2 = pl$DataFrame(iris) -#' dat3 = pl$DataFrame(mtcars) +#' dat1 = as_polars_df(iris) +#' dat2 = as_polars_df(iris) +#' dat3 = as_polars_df(mtcars) #' dat1$equals(dat2) #' dat1$equals(dat3) DataFrame_equals = function(other) { @@ -814,7 +803,7 @@ DataFrame_shift = function(n = 1, fill_value = NULL) { #' @keywords DataFrame #' @return A DataFrame #' @examples -#' pl$DataFrame(iris)$with_columns( +#' as_polars_df(iris)$with_columns( #' pl$col("Sepal.Length")$abs()$alias("abs_SL"), #' (pl$col("Sepal.Length") + 2)$alias("add_2_SL") #' ) @@ -824,9 +813,9 @@ DataFrame_shift = function(n = 1, fill_value = NULL) { #' pl$col("Sepal.Length")$abs()$alias("abs_SL"), #' (pl$col("Sepal.Length") + 2)$alias("add_2_SL") #' ) -#' pl$DataFrame(iris)$with_columns(l_expr) +#' as_polars_df(iris)$with_columns(l_expr) #' -#' pl$DataFrame(iris)$with_columns( +#' as_polars_df(iris)$with_columns( #' pl$col("Sepal.Length")$abs(), # not named expr will keep name "Sepal.Length" #' SW_add_2 = (pl$col("Sepal.Width") + 2) #' ) @@ -847,7 +836,7 @@ DataFrame_with_columns = function(...) { #' preferred. #' #' @examples -#' pl$DataFrame(iris)$with_columns_seq( +#' as_polars_df(iris)$with_columns_seq( #' pl$col("Sepal.Length")$abs()$alias("abs_SL"), #' (pl$col("Sepal.Length") + 2)$alias("add_2_SL") #' ) @@ -857,9 +846,9 @@ DataFrame_with_columns = function(...) { #' pl$col("Sepal.Length")$abs()$alias("abs_SL"), #' (pl$col("Sepal.Length") + 2)$alias("add_2_SL") #' ) -#' pl$DataFrame(iris)$with_columns_seq(l_expr) +#' as_polars_df(iris)$with_columns_seq(l_expr) #' -#' pl$DataFrame(iris)$with_columns_seq( +#' as_polars_df(iris)$with_columns_seq( #' pl$col("Sepal.Length")$abs(), # not named expr will keep name "Sepal.Length" #' SW_add_2 = (pl$col("Sepal.Width") + 2) #' ) @@ -914,7 +903,7 @@ DataFrame_tail = function(n = 5L) { #' @keywords DataFrame #' @return A DataFrame with only the rows where the conditions are `TRUE`. #' @examples -#' df = pl$DataFrame(iris) +#' df = as_polars_df(iris) #' #' df$filter(pl$col("Sepal.Length") > 5) #' @@ -925,7 +914,7 @@ DataFrame_tail = function(n = 5L) { #' # rows where condition is NA are dropped #' iris2 = iris #' iris2[c(1, 3, 5), "Species"] = NA -#' df = pl$DataFrame(iris2) +#' df = as_polars_df(iris2) #' #' df$filter(pl$col("Species") == "setosa") DataFrame_filter = function(...) { @@ -990,7 +979,7 @@ DataFrame_group_by = function(..., maintain_order = polars_options()$maintain_or #' @inheritSection DataFrame_class Conversion to R data types considerations #' @keywords DataFrame #' @examples -#' df = pl$DataFrame(iris[1:3, ]) +#' df = as_polars_df(iris[1:3, ]) #' df$to_data_frame() DataFrame_to_data_frame = function(..., int64_conversion = polars_options()$int64_conversion) { # do not unnest structs and mark with I to also preserve categoricals as is @@ -1035,7 +1024,7 @@ DataFrame_to_data_frame = function(..., int64_conversion = polars_options()$int6 #' - [`$get_columns()`][DataFrame_get_columns]: #' Similar to this method but returns a list of [Series][Series_class] instead of vectors. #' @examples -#' pl$DataFrame(iris)$to_list() +#' as_polars_df(iris)$to_list() DataFrame_to_list = function(unnest_structs = TRUE, ..., int64_conversion = polars_options()$int64_conversion) { if (unnest_structs) { .pr$DataFrame$to_list(self, int64_conversion) |> @@ -1147,7 +1136,7 @@ DataFrame_unnest = function(...) { #' @title Get the first row of the DataFrame. #' @keywords DataFrame #' @return A DataFrame with one row. -#' @examples pl$DataFrame(mtcars)$first() +#' @examples as_polars_df(mtcars)$first() DataFrame_first = function() { self$lazy()$first()$collect() } @@ -1237,7 +1226,7 @@ DataFrame_rechunk = function() { #' @title Get the last row of the DataFrame. #' @keywords DataFrame #' @return A DataFrame with one row. -#' @examples pl$DataFrame(mtcars)$last() +#' @examples as_polars_df(mtcars)$last() DataFrame_last = function() { self$lazy()$last()$collect() } @@ -1246,7 +1235,7 @@ DataFrame_last = function() { #' @description Aggregate the columns in the DataFrame to their maximum value. #' @keywords DataFrame #' @return A DataFrame with one row. -#' @examples pl$DataFrame(mtcars)$max() +#' @examples as_polars_df(mtcars)$max() DataFrame_max = function() { self$lazy()$max()$collect() } @@ -1255,7 +1244,7 @@ DataFrame_max = function() { #' @description Aggregate the columns in the DataFrame to their mean value. #' @keywords DataFrame #' @return A DataFrame with one row. -#' @examples pl$DataFrame(mtcars)$mean() +#' @examples as_polars_df(mtcars)$mean() DataFrame_mean = function() { self$lazy()$mean()$collect() } @@ -1264,7 +1253,7 @@ DataFrame_mean = function() { #' @description Aggregate the columns in the DataFrame to their median value. #' @keywords DataFrame #' @return A DataFrame with one row. -#' @examples pl$DataFrame(mtcars)$median() +#' @examples as_polars_df(mtcars)$median() DataFrame_median = function() { self$lazy()$median()$collect() } @@ -1273,7 +1262,7 @@ DataFrame_median = function() { #' @description Aggregate the columns in the DataFrame to their minimum value. #' @keywords DataFrame #' @return A DataFrame with one row. -#' @examples pl$DataFrame(mtcars)$min() +#' @examples as_polars_df(mtcars)$min() DataFrame_min = function() { self$lazy()$min()$collect() } @@ -1282,7 +1271,7 @@ DataFrame_min = function() { #' @description Aggregate the columns of this DataFrame to their sum values. #' @keywords DataFrame #' @return A DataFrame with one row. -#' @examples pl$DataFrame(mtcars)$sum() +#' @examples as_polars_df(mtcars)$sum() DataFrame_sum = function() { self$lazy()$sum()$collect() } @@ -1293,7 +1282,7 @@ DataFrame_sum = function() { #' @param ddof Delta Degrees of Freedom: the divisor used in the calculation is #' N - ddof, where N represents the number of elements. By default ddof is 1. #' @return A DataFrame with one row. -#' @examples pl$DataFrame(mtcars)$var() +#' @examples as_polars_df(mtcars)$var() DataFrame_var = function(ddof = 1) { self$lazy()$var(ddof)$collect() } @@ -1305,7 +1294,7 @@ DataFrame_var = function(ddof = 1) { #' @param ddof Delta Degrees of Freedom: the divisor used in the calculation is #' N - ddof, where N represents the number of elements. By default ddof is 1. #' @return A DataFrame with one row. -#' @examples pl$DataFrame(mtcars)$std() +#' @examples as_polars_df(mtcars)$std() DataFrame_std = function(ddof = 1) { self$lazy()$std(ddof)$collect() } @@ -1317,7 +1306,7 @@ DataFrame_std = function(ddof = 1) { #' @param quantile Numeric of length 1 between 0 and 1. #' @inheritParams Expr_quantile #' @return DataFrame -#' @examples pl$DataFrame(mtcars)$quantile(.4) +#' @examples as_polars_df(mtcars)$quantile(.4) DataFrame_quantile = function(quantile, interpolation = "nearest") { self$lazy()$quantile(quantile, interpolation)$collect() } @@ -1325,7 +1314,7 @@ DataFrame_quantile = function(quantile, interpolation = "nearest") { #' @title Reverse #' @description Reverse the DataFrame (the last row becomes the first one, etc.). #' @return DataFrame -#' @examples pl$DataFrame(mtcars)$reverse() +#' @examples as_polars_df(mtcars)$reverse() DataFrame_reverse = function() { self$lazy()$reverse()$collect() } @@ -1371,7 +1360,7 @@ DataFrame_fill_null = function(fill_value) { #' the offset will be selected. #' @examples #' # skip the first 2 rows and take the 4 following rows -#' pl$DataFrame(mtcars)$slice(2, 4) +#' as_polars_df(mtcars)$slice(2, 4) #' #' # this is equivalent to: #' mtcars[3:6, ] @@ -1404,7 +1393,7 @@ DataFrame_null_count = use_extendr_wrapper #' @format NULL #' @format function #' @examples -#' pl$DataFrame(mtcars)$estimated_size() +#' as_polars_df(mtcars)$estimated_size() DataFrame_estimated_size = use_extendr_wrapper @@ -1625,7 +1614,7 @@ DataFrame_rename = function(...) { #' @keywords DataFrame #' @return DataFrame #' @examples -#' pl$DataFrame(iris)$describe() +#' as_polars_df(iris)$describe() #' #' # string, date, boolean columns are also supported: #' df = pl$DataFrame( @@ -1758,7 +1747,7 @@ DataFrame_describe = function(percentiles = c(0.25, 0.75), interpolation = "near #' #' @return DataFrame #' @examples -#' pl$DataFrame(iris)$glimpse() +#' as_polars_df(iris)$glimpse() DataFrame_glimpse = function( ..., max_items_per_column = 10, @@ -1853,7 +1842,7 @@ DataFrame_explode = function(...) { #' @keywords DataFrame #' @return DataFrame #' @examples -#' df = pl$DataFrame(iris) +#' df = as_polars_df(iris) #' df$sample(n = 20) #' df$sample(fraction = 0.1) DataFrame_sample = function(n = NULL, ..., fraction = NULL, with_replacement = FALSE, shuffle = FALSE, seed = NULL) { @@ -1890,11 +1879,11 @@ DataFrame_sample = function(n = NULL, ..., fraction = NULL, with_replacement = F #' @examples #' #' # simple use-case -#' pl$DataFrame(mtcars)$transpose(include_header = TRUE, column_names = rownames(mtcars)) +#' as_polars_df(mtcars)$transpose(include_header = TRUE, column_names = rownames(mtcars)) #' #' # All rows must have one shared supertype, recast Categorical to String which is a supertype #' # of f64, and then dataset "Iris" can be transposed -#' pl$DataFrame(iris)$with_columns(pl$col("Species")$cast(pl$String))$transpose() +#' as_polars_df(iris)$with_columns(pl$col("Species")$cast(pl$String))$transpose() #' DataFrame_transpose = function( include_header = FALSE, @@ -1946,7 +1935,7 @@ DataFrame_transpose = function( #' @rdname IO_write_csv #' #' @examples -#' dat = pl$DataFrame(mtcars) +#' dat = as_polars_df(mtcars) #' #' destination = tempfile(fileext = ".csv") #' dat$select(pl$col("drat", "mpg"))$write_csv(destination) @@ -1994,7 +1983,7 @@ DataFrame_write_csv = function( #' @seealso #' - [`$to_raw_ipc()`][DataFrame_to_raw_ipc] #' @examples -#' dat = pl$DataFrame(mtcars) +#' dat = as_polars_df(mtcars) #' #' destination = tempfile(fileext = ".arrow") #' dat$write_ipc(destination) @@ -2035,7 +2024,7 @@ DataFrame_write_ipc = function( #' @rdname IO_write_parquet #' #' @examplesIf requireNamespace("withr", quietly = TRUE) -#' dat = pl$DataFrame(mtcars) +#' dat = as_polars_df(mtcars) #' #' # write data to a single parquet file #' destination = withr::local_tempfile(fileext = ".parquet") @@ -2084,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) @@ -2112,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) diff --git a/R/datatype.R b/R/datatype.R index dda7996c0..2d931c32a 100644 --- a/R/datatype.R +++ b/R/datatype.R @@ -3,7 +3,7 @@ #' @return bool #' @keywords functions #' @examples -#' pl$is_schema(pl$DataFrame(iris)$schema) +#' pl$is_schema(as_polars_df(iris)$schema) #' pl$is_schema(list("alice", "bob")) pl_is_schema = \(x) { is.list(x) && !is.null(names(x)) && !anyNA(names(x)) && diff --git a/R/expr__expr.R b/R/expr__expr.R index 06b72edda..185f93dba 100644 --- a/R/expr__expr.R +++ b/R/expr__expr.R @@ -715,7 +715,7 @@ Expr_is_not_null = use_extendr_wrapper #' `polars_options()$rpool_cap` to set and view number of parallel R sessions. #' #' @examples -#' pl$DataFrame(iris)$ +#' as_polars_df(iris)$ #' select( #' pl$col("Sepal.Length")$map_batches(\(x) { #' paste("cheese", as.character(x$to_vector())) @@ -819,7 +819,7 @@ Expr_map_batches = function(f, output_type = NULL, agg_list = FALSE, in_backgrou #' # get the first two values of each variable and store them in a list #' e_sum = pl$all()$map_elements(\(s) sum(s$to_r()))$name$suffix("_sum") #' e_head = pl$all()$map_elements(\(s) head(s$to_r(), 2))$name$suffix("_head") -#' pl$DataFrame(iris)$group_by("Species")$agg(e_sum, e_head) +#' as_polars_df(iris)$group_by("Species")$agg(e_sum, e_head) #' #' # apply a function on each value (should be avoided): here the input is an R #' # value of length 1 @@ -835,7 +835,7 @@ Expr_map_batches = function(f, output_type = NULL, agg_list = FALSE, in_backgrou #' e_letter = my_selection$map_elements(\(x) { #' letters[ceiling(x)] #' }, return_type = pl$dtypes$String)$name$suffix("_letter") -#' pl$DataFrame(iris)$select(e_add10, e_letter) +#' as_polars_df(iris)$select(e_add10, e_letter) #' #' #' # Small benchmark -------------------------------- @@ -872,7 +872,7 @@ Expr_map_batches = function(f, output_type = NULL, agg_list = FALSE, in_backgrou #' # use apply over each Species-group in each column equal to 12 sequential #' # runs ~1.2 sec. #' system.time({ -#' pl$LazyFrame(iris)$group_by("Species")$agg( +#' as_polars_lf(iris)$group_by("Species")$agg( #' pl$all()$map_elements(\(s) { #' Sys.sleep(.1) #' s$sum() @@ -888,7 +888,7 @@ Expr_map_batches = function(f, output_type = NULL, agg_list = FALSE, in_backgrou #' polars_options()$rpool_cap #' #' system.time({ -#' pl$LazyFrame(iris)$group_by("Species")$agg( +#' as_polars_lf(iris)$group_by("Species")$agg( #' pl$all()$map_elements(\(s) { #' Sys.sleep(.1) #' s$sum() @@ -899,7 +899,7 @@ Expr_map_batches = function(f, output_type = NULL, agg_list = FALSE, in_backgrou #' # second run in parallel: this reuses R processes in "polars global_rpool". #' polars_options()$rpool_cap #' system.time({ -#' pl$LazyFrame(iris)$group_by("Species")$agg( +#' as_polars_lf(iris)$group_by("Species")$agg( #' pl$all()$map_elements(\(s) { #' Sys.sleep(.1) #' s$sum() @@ -1069,7 +1069,7 @@ Expr_exp = use_extendr_wrapper #' @examples #' #' # make DataFrame -#' df = pl$DataFrame(iris) +#' df = as_polars_df(iris) #' #' # by name(s) #' df$select(pl$all()$exclude("Species")) @@ -1176,7 +1176,7 @@ Expr_is_not_nan = use_extendr_wrapper #' ) #' #' # recycling -#' pl$DataFrame(mtcars)$with_columns(pl$col("mpg")$slice(0, 1)$first()) +#' as_polars_df(mtcars)$with_columns(pl$col("mpg")$slice(0, 1)$first()) Expr_slice = function(offset, length = NULL) { .pr$Expr$slice(self, offset, wrap_e(length)) |> unwrap("in $slice():") @@ -1750,7 +1750,7 @@ Expr_product = use_extendr_wrapper #' #' @return Expr #' @examples -#' pl$DataFrame(iris[, 4:5])$with_columns(count = pl$col("Species")$n_unique()) +#' as_polars_df(iris[, 4:5])$with_columns(count = pl$col("Species")$n_unique()) Expr_n_unique = use_extendr_wrapper #' Approx count unique values @@ -1758,7 +1758,7 @@ Expr_n_unique = use_extendr_wrapper #' This is done using the HyperLogLog++ algorithm for cardinality estimation. #' @return Expr #' @examples -#' pl$DataFrame(iris[, 4:5])$ +#' as_polars_df(iris[, 4:5])$ #' with_columns(count = pl$col("Species")$approx_n_unique()) Expr_approx_n_unique = use_extendr_wrapper @@ -1785,7 +1785,7 @@ Expr_arg_unique = use_extendr_wrapper #' appearance. #' @return Expr #' @examples -#' pl$DataFrame(iris)$select(pl$col("Species")$unique()) +#' as_polars_df(iris)$select(pl$col("Species")$unique()) Expr_unique = function(maintain_order = FALSE) { if (!is_scalar_bool(maintain_order)) stop("param maintain_order must be a bool") if (maintain_order) { @@ -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 @@ -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 @@ -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 @@ -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 @@ -2156,7 +2156,7 @@ Expr_is_between = function(lower_bound, upper_bound, closed = "both") { #' @return Expr #' @aliases hash #' @examples -#' df = pl$DataFrame(iris[1:3, c(1, 2)]) +#' df = as_polars_df(iris[1:3, c(1, 2)]) #' df$with_columns(pl$all()$hash(1234)$name$suffix("_hash")) Expr_hash = function(seed = 0, seed_1 = NULL, seed_2 = NULL, seed_3 = NULL) { k0 = seed @@ -3293,7 +3293,7 @@ Expr_to_r = function(df = NULL, i = 0, ..., int64_conversion = polars_options()$ #' values instead of their count. #' #' @examples -#' df = pl$DataFrame(iris) +#' df = as_polars_df(iris) #' df$select(pl$col("Species")$value_counts())$unnest() #' df$select(pl$col("Species")$value_counts(normalize = TRUE))$unnest() Expr_value_counts = function(..., sort = FALSE, parallel = FALSE, name, normalize = FALSE) { @@ -3315,7 +3315,7 @@ Expr_value_counts = function(..., sort = FALSE, parallel = FALSE, name, normaliz #' the counts and it might be faster. #' @return Expr #' @examples -#' pl$DataFrame(iris)$select(pl$col("Species")$unique_counts()) +#' as_polars_df(iris)$select(pl$col("Species")$unique_counts()) Expr_unique_counts = use_extendr_wrapper #' Compute the logarithm of elements diff --git a/R/expr__name.R b/R/expr__name.R index 5e7c53a26..2fe09ceb0 100644 --- a/R/expr__name.R +++ b/R/expr__name.R @@ -6,7 +6,7 @@ #' [`$prefix()`][ExprName_prefix] to add a prefix #' #' @examples -#' dat = pl$DataFrame(mtcars) +#' dat = as_polars_df(mtcars) #' #' dat$select( #' pl$col("mpg"), @@ -26,7 +26,7 @@ ExprName_suffix = function(suffix) { #' [`$suffix()`][ExprName_suffix] to add a suffix #' #' @examples -#' dat = pl$DataFrame(mtcars) +#' dat = as_polars_df(mtcars) #' #' dat$select( #' pl$col("mpg"), diff --git a/R/functions__lazy.R b/R/functions__lazy.R index 3b3bf981d..e893f045c 100644 --- a/R/functions__lazy.R +++ b/R/functions__lazy.R @@ -192,7 +192,7 @@ pl_count = function(...) { #' @inheritParams pl_head #' @inherit pl_head return #' @examples -#' pl$DataFrame(iris)$select(pl$implode("Species")) +#' as_polars_df(iris)$select(pl$implode("Species")) pl_implode = function(...) { result(pl$col(...)$implode()) |> unwrap("in pl$implode():") @@ -708,7 +708,7 @@ pl_concat_str = function(..., separator = "", ignore_nulls = FALSE) { #' @return Expr for the computed covariance #' @examples -#' lf = pl$LazyFrame(data.frame(a = c(1, 8, 3), b = c(4, 5, 2))) +#' lf = as_polars_lf(data.frame(a = c(1, 8, 3), b = c(4, 5, 2))) #' lf$select(pl$cov("a", "b"))$collect() #' pl$cov(c(1, 8, 3), c(4, 5, 2))$to_r() pl_cov = function(a, b, ddof = 1) { @@ -726,7 +726,7 @@ pl_cov = function(a, b, ddof = 1) { #' @param ddof integer Delta Degrees of Freedom: the divisor used in the calculation is N - ddof, where N represents the number of elements. By default ddof is 1. #' @return Expr for the computed rolling covariance #' @examples -#' lf = pl$LazyFrame(data.frame(a = c(1, 8, 3), b = c(4, 5, 2))) +#' lf = as_polars_lf(data.frame(a = c(1, 8, 3), b = c(4, 5, 2))) #' lf$select(pl$rolling_cov("a", "b", window_size = 2))$collect() pl_rolling_cov = function(a, b, window_size, min_periods = NULL, ddof = 1) { if (is.null(min_periods)) { @@ -747,7 +747,7 @@ pl_rolling_cov = function(a, b, window_size, min_periods = NULL, ddof = 1) { #' Defaults to `False` where `NaN` are regarded as larger than any finite number and thus lead to the highest rank. #' @return Expr for the computed correlation #' @examples -#' lf = pl$LazyFrame(data.frame(a = c(1, 8, 3), b = c(4, 5, 2))) +#' lf = as_polars_lf(data.frame(a = c(1, 8, 3), b = c(4, 5, 2))) #' lf$select(pl$corr("a", "b", method = "spearman"))$collect() pl_corr = function(a, b, method = "pearson", ddof = 1, propagate_nans = FALSE) { .pr$Expr$corr(a, b, method, ddof, propagate_nans) |> unwrap("in pl$corr()") @@ -763,7 +763,7 @@ pl_corr = function(a, b, method = "pearson", ddof = 1, propagate_nans = FALSE) { #' @param ddof integer Delta Degrees of Freedom: the divisor used in the calculation is N - ddof, where N represents the number of elements. By default ddof is 1. #' @return Expr for the computed rolling correlation #' @examples -#' lf = pl$LazyFrame(data.frame(a = c(1, 8, 3), b = c(4, 5, 2))) +#' lf = as_polars_lf(data.frame(a = c(1, 8, 3), b = c(4, 5, 2))) #' lf$select(pl$rolling_corr("a", "b", window_size = 2))$collect() pl_rolling_corr = function(a, b, window_size, min_periods = NULL, ddof = 1) { if (is.null(min_periods)) { @@ -786,7 +786,7 @@ pl_rolling_corr = function(a, b, window_size, min_periods = NULL, ddof = 1) { #' @return An expression that will be applied rowwise #' #' @examples -#' df = pl$DataFrame(mtcars) +#' df = as_polars_df(mtcars) #' #' # Make the row-wise sum of all columns #' df$with_columns( @@ -808,7 +808,7 @@ pl_fold = function(acc, lambda, exprs) { #' operations with an initial value. #' #' @examples -#' df = pl$DataFrame(mtcars) +#' df = as_polars_df(mtcars) #' #' # Make the row-wise sum of all columns #' df$with_columns( diff --git a/R/group_by.R b/R/group_by.R index 8e80505da..6d3d9fb89 100644 --- a/R/group_by.R +++ b/R/group_by.R @@ -82,7 +82,7 @@ construct_group_by = function(df, groupby_input, maintain_order) { #' @export #' #' @examples -#' pl$DataFrame(iris)$group_by("Species") +#' as_polars_df(iris)$group_by("Species") print.RPolarsGroupBy = function(x, ...) { prv = attr(x, "private") .pr$DataFrame$print(prv$dat) @@ -267,7 +267,7 @@ GroupBy_std = function() { #' @param quantile numeric Quantile between 0.0 and 1.0. #' @param interpolation string Interpolation method: "nearest", "higher", "lower", "midpoint", or "linear". #' @return GroupBy -#' @examples pl$DataFrame(mtcars)$lazy()$quantile(.4)$collect() +#' @examples as_polars_df(mtcars)$lazy()$quantile(.4)$collect() GroupBy_quantile = function(quantile, interpolation = "nearest") { self$agg(pl$all()$quantile(quantile, interpolation)) } @@ -278,7 +278,7 @@ GroupBy_quantile = function(quantile, interpolation = "nearest") { #' #' @return GroupBy #' @examples -#' pl$DataFrame(mtcars)$group_by("cyl")$shift(2) +#' as_polars_df(mtcars)$group_by("cyl")$shift(2) GroupBy_shift = function(n = 1, fill_value = NULL) { self$agg(pl$all()$shift(n, fill_value)) } @@ -301,7 +301,7 @@ GroupBy_null_count = function() { #' Revert the group by operation. #' @return [DataFrame][DataFrame_class] #' @examples -#' gb = pl$DataFrame(mtcars)$group_by("cyl") +#' gb = as_polars_df(mtcars)$group_by("cyl") #' gb #' #' gb$ungroup() diff --git a/R/io_parquet.R b/R/io_parquet.R index 58f919ed4..bc8548e97 100644 --- a/R/io_parquet.R +++ b/R/io_parquet.R @@ -73,13 +73,13 @@ #' @examplesIf requireNamespace("withr", quietly = TRUE) #' # Write a Parquet file than we can then import as DataFrame #' temp_file = withr::local_tempfile(fileext = ".parquet") -#' pl$DataFrame(mtcars)$write_parquet(temp_file) +#' as_polars_df(mtcars)$write_parquet(temp_file) #' #' pl$scan_parquet(temp_file)$collect() #' #' # Write a hive-style partitioned parquet dataset #' temp_dir = withr::local_tempdir() -#' pl$DataFrame(mtcars)$write_parquet(temp_dir, partition_by = c("cyl", "gear")) +#' as_polars_df(mtcars)$write_parquet(temp_dir, partition_by = c("cyl", "gear")) #' list.files(temp_dir, recursive = TRUE) #' #' # If the path is a folder, Polars automatically tries to detect partitions @@ -134,13 +134,13 @@ pl_scan_parquet = function( #' @examplesIf requireNamespace("withr", quietly = TRUE) #' # Write a Parquet file than we can then import as DataFrame #' temp_file = withr::local_tempfile(fileext = ".parquet") -#' pl$DataFrame(mtcars)$write_parquet(temp_file) +#' as_polars_df(mtcars)$write_parquet(temp_file) #' #' pl$read_parquet(temp_file) #' #' # Write a hive-style partitioned parquet dataset #' temp_dir = withr::local_tempdir() -#' pl$DataFrame(mtcars)$write_parquet(temp_dir, partition_by = c("cyl", "gear")) +#' as_polars_df(mtcars)$write_parquet(temp_dir, partition_by = c("cyl", "gear")) #' list.files(temp_dir, recursive = TRUE) #' #' # If the path is a folder, Polars automatically tries to detect partitions diff --git a/R/lazyframe__group_by.R b/R/lazyframe__group_by.R index 9c4e44127..910718d73 100644 --- a/R/lazyframe__group_by.R +++ b/R/lazyframe__group_by.R @@ -111,7 +111,7 @@ LazyGroupBy_print = function() { #' Revert the group by operation. #' @inherit LazyGroupBy_agg return #' @examples -#' lf = pl$LazyFrame(mtcars) +#' lf = as_polars_lf(mtcars) #' lf #' #' lgb = lf$group_by("cyl") diff --git a/R/lazyframe__lazy.R b/R/lazyframe__lazy.R index e7d10eb5a..2e3e69b9a 100644 --- a/R/lazyframe__lazy.R +++ b/R/lazyframe__lazy.R @@ -206,7 +206,7 @@ pl_LazyFrame = function(...) { #' @return self #' @export #' -#' @examples pl$LazyFrame(iris) +#' @examples as_polars_lf(iris) print.RPolarsLazyFrame = function(x, ...) { cat("polars LazyFrame\n") cat(" $explain(): Show the optimized query plan.\n") @@ -225,7 +225,7 @@ print.RPolarsLazyFrame = function(x, ...) { #' @docType NULL #' #' @usage LazyFrame_print(x) -#' @examples pl$LazyFrame(iris)$print() +#' @examples as_polars_lf(iris)$print() LazyFrame_print = function() { .pr$LazyFrame$print(self) |> unwrap("in $print():") @@ -266,7 +266,7 @@ LazyFrame_print = function() { #' #' @return A character value containing the query plan. #' @examples -#' lazy_frame = pl$LazyFrame(iris) +#' lazy_frame = as_polars_lf(iris) #' #' # Prepare your query #' lazy_query = lazy_frame$sort("Species")$filter(pl$col("Species") != "setosa") @@ -381,7 +381,7 @@ pl_deserialize_lf = function(json) { #' @inherit DataFrame_select description params #' @return A LazyFrame #' @examples -#' pl$LazyFrame(iris)$select( +#' as_polars_lf(iris)$select( #' pl$col("Sepal.Length")$abs()$alias("abs_SL"), #' (pl$col("Sepal.Length") + 2)$alias("add_2_SL") #' ) @@ -394,7 +394,7 @@ LazyFrame_select = function(...) { #' @inherit DataFrame_select_seq description params #' @return A LazyFrame #' @examples -#' pl$LazyFrame(iris)$select_seq( +#' as_polars_lf(iris)$select_seq( #' pl$col("Sepal.Length")$abs()$alias("abs_SL"), #' (pl$col("Sepal.Length") + 2)$alias("add_2_SL") #' ) @@ -409,7 +409,7 @@ LazyFrame_select_seq = function(...) { #' #' @return A LazyFrame #' @examples -#' pl$LazyFrame(iris)$with_columns( +#' as_polars_lf(iris)$with_columns( #' pl$col("Sepal.Length")$abs()$alias("abs_SL"), #' (pl$col("Sepal.Length") + 2)$alias("add_2_SL") #' ) @@ -419,9 +419,9 @@ LazyFrame_select_seq = function(...) { #' pl$col("Sepal.Length")$abs()$alias("abs_SL"), #' (pl$col("Sepal.Length") + 2)$alias("add_2_SL") #' ) -#' pl$LazyFrame(iris)$with_columns(l_expr) +#' as_polars_lf(iris)$with_columns(l_expr) #' -#' pl$LazyFrame(iris)$with_columns( +#' as_polars_lf(iris)$with_columns( #' pl$col("Sepal.Length")$abs(), # not named expr will keep name "Sepal.Length" #' SW_add_2 = (pl$col("Sepal.Width") + 2) #' ) @@ -435,7 +435,7 @@ LazyFrame_with_columns = function(...) { #' #' @return A LazyFrame #' @examples -#' pl$LazyFrame(iris)$with_columns_seq( +#' as_polars_lf(iris)$with_columns_seq( #' pl$col("Sepal.Length")$abs()$alias("abs_SL"), #' (pl$col("Sepal.Length") + 2)$alias("add_2_SL") #' ) @@ -445,9 +445,9 @@ LazyFrame_with_columns = function(...) { #' pl$col("Sepal.Length")$abs()$alias("abs_SL"), #' (pl$col("Sepal.Length") + 2)$alias("add_2_SL") #' ) -#' pl$LazyFrame(iris)$with_columns_seq(l_expr) +#' as_polars_lf(iris)$with_columns_seq(l_expr) #' -#' pl$LazyFrame(iris)$with_columns_seq( +#' as_polars_lf(iris)$with_columns_seq( #' pl$col("Sepal.Length")$abs(), # not named expr will keep name "Sepal.Length" #' SW_add_2 = (pl$col("Sepal.Width") + 2) #' ) @@ -461,7 +461,7 @@ LazyFrame_with_columns_seq = function(...) { #' @return A new LazyFrame with a counter column in front #' @docType NULL #' @examples -#' df = pl$LazyFrame(mtcars) +#' df = as_polars_lf(mtcars) #' #' # by default, the index starts at 0 (to mimic the behavior of Python Polars) #' df$with_row_index("idx") @@ -486,7 +486,7 @@ LazyFrame_with_row_index = function(name, offset = NULL) { #' @return A new `LazyFrame` object with add/modified column. #' @docType NULL #' @examples -#' lf = pl$LazyFrame(iris) +#' lf = as_polars_lf(iris) #' #' lf$filter(pl$col("Species") == "setosa")$collect() #' @@ -518,7 +518,7 @@ LazyFrame_filter = function(...) { #' @keywords LazyFrame DataFrame_new #' @return A `DataFrame` #' @examples -#' pl$LazyFrame(iris)$filter(pl$col("Species") == "setosa")$collect() +#' as_polars_lf(iris)$filter(pl$col("Species") == "setosa")$collect() #' @seealso #' - [`$fetch()`][LazyFrame_fetch] - fast limited query check #' - [`$profile()`][LazyFrame_profile] - same as `$collect()` but also returns @@ -608,7 +608,7 @@ LazyFrame_collect = function( #' )$alias("kml") #' #' # return is immediately a handle to another thread. -#' handle = pl$LazyFrame(mtcars)$with_columns(expr)$collect_in_background() +#' handle = as_polars_lf(mtcars)$with_columns(expr)$collect_in_background() #' #' # ask if query is done #' if (!handle$is_finished()) print("not done yet") @@ -668,7 +668,7 @@ LazyFrame_collect_in_background = function() { #' @examples #' # sink table 'mtcars' from mem to parquet #' tmpf = tempfile() -#' pl$LazyFrame(mtcars)$sink_parquet(tmpf) +#' as_polars_lf(mtcars)$sink_parquet(tmpf) #' #' # stream a query end-to-end #' tmpf2 = tempfile() @@ -752,7 +752,7 @@ LazyFrame_sink_parquet = function( #' @examples #' # sink table 'mtcars' from mem to ipc #' tmpf = tempfile() -#' pl$LazyFrame(mtcars)$sink_ipc(tmpf) +#' as_polars_lf(mtcars)$sink_ipc(tmpf) #' #' # stream a query end-to-end (not supported yet, https://github.com/pola-rs/polars/issues/1040) #' # tmpf2 = tempfile() @@ -822,7 +822,7 @@ LazyFrame_sink_ipc = function( #' @examples #' # sink table 'mtcars' from mem to CSV #' tmpf = tempfile() -#' pl$LazyFrame(mtcars)$sink_csv(tmpf) +#' as_polars_lf(mtcars)$sink_csv(tmpf) #' #' # stream a query end-to-end #' tmpf2 = tempfile() @@ -914,7 +914,7 @@ LazyFrame_sink_csv = function( #' @examples #' # sink table 'mtcars' from mem to JSON #' tmpf = tempfile(fileext = ".json") -#' pl$LazyFrame(mtcars)$sink_ndjson(tmpf) +#' as_polars_lf(mtcars)$sink_ndjson(tmpf) #' #' # load parquet directly into a DataFrame / memory #' pl$scan_ndjson(tmpf)$collect() @@ -990,7 +990,7 @@ LazyFrame_limit = LazyFrame_head #' @return A LazyFrame with one row #' @docType NULL #' @format NULL -#' @examples pl$LazyFrame(mtcars)$first()$collect() +#' @examples as_polars_lf(mtcars)$first()$collect() LazyFrame_first = use_extendr_wrapper #' @title Get the last row of a LazyFrame @@ -999,7 +999,7 @@ LazyFrame_first = use_extendr_wrapper #' @return A LazyFrame with one row #' @docType NULL #' @format NULL -#' @examples pl$LazyFrame(mtcars)$last()$collect() +#' @examples as_polars_lf(mtcars)$last()$collect() LazyFrame_last = use_extendr_wrapper #' @title Max @@ -1008,7 +1008,7 @@ LazyFrame_last = use_extendr_wrapper #' @return A LazyFrame with one row #' @docType NULL #' @format NULL -#' @examples pl$LazyFrame(mtcars)$max()$collect() +#' @examples as_polars_lf(mtcars)$max()$collect() LazyFrame_max = use_extendr_wrapper #' @title Mean @@ -1017,7 +1017,7 @@ LazyFrame_max = use_extendr_wrapper #' @return A LazyFrame with one row #' @docType NULL #' @format NULL -#' @examples pl$LazyFrame(mtcars)$mean()$collect() +#' @examples as_polars_lf(mtcars)$mean()$collect() LazyFrame_mean = use_extendr_wrapper #' @title Median @@ -1026,7 +1026,7 @@ LazyFrame_mean = use_extendr_wrapper #' @return A LazyFrame with one row #' @docType NULL #' @format NULL -#' @examples pl$LazyFrame(mtcars)$median()$collect() +#' @examples as_polars_lf(mtcars)$median()$collect() LazyFrame_median = use_extendr_wrapper #' @title Min @@ -1035,7 +1035,7 @@ LazyFrame_median = use_extendr_wrapper #' @return A LazyFrame with one row #' @docType NULL #' @format NULL -#' @examples pl$LazyFrame(mtcars)$min()$collect() +#' @examples as_polars_lf(mtcars)$min()$collect() LazyFrame_min = use_extendr_wrapper #' @title Sum @@ -1044,7 +1044,7 @@ LazyFrame_min = use_extendr_wrapper #' @return A LazyFrame with one row #' @docType NULL #' @format NULL -#' @examples pl$LazyFrame(mtcars)$sum()$collect() +#' @examples as_polars_lf(mtcars)$sum()$collect() LazyFrame_sum = use_extendr_wrapper #' @title Var @@ -1052,7 +1052,7 @@ LazyFrame_sum = use_extendr_wrapper #' @keywords LazyFrame #' @inheritParams DataFrame_var #' @return A LazyFrame with one row -#' @examples pl$LazyFrame(mtcars)$var()$collect() +#' @examples as_polars_lf(mtcars)$var()$collect() LazyFrame_var = function(ddof = 1) { unwrap(.pr$LazyFrame$var(self, ddof), "in $var():") } @@ -1063,7 +1063,7 @@ LazyFrame_var = function(ddof = 1) { #' @keywords LazyFrame #' @inheritParams DataFrame_std #' @return A LazyFrame with one row -#' @examples pl$LazyFrame(mtcars)$std()$collect() +#' @examples as_polars_lf(mtcars)$std()$collect() LazyFrame_std = function(ddof = 1) { unwrap(.pr$LazyFrame$std(self, ddof), "in $std():") } @@ -1073,7 +1073,7 @@ LazyFrame_std = function(ddof = 1) { #' value. Use `$describe()` to specify several quantiles. #' @inheritParams DataFrame_quantile #' @return LazyFrame -#' @examples pl$LazyFrame(mtcars)$quantile(.4)$collect() +#' @examples as_polars_lf(mtcars)$quantile(.4)$collect() LazyFrame_quantile = function(quantile, interpolation = "nearest") { unwrap(.pr$LazyFrame$quantile(self, wrap_e_result(quantile), interpolation), "in $quantile():") } @@ -1128,10 +1128,10 @@ LazyFrame_shift = function(n = 1, fill_value = NULL) { #' #' @return LazyFrame #' @examples -#' pl$LazyFrame(mtcars)$drop(c("mpg", "hp"))$collect() +#' as_polars_lf(mtcars)$drop(c("mpg", "hp"))$collect() #' #' # equivalent -#' pl$LazyFrame(mtcars)$drop("mpg", "hp")$collect() +#' as_polars_lf(mtcars)$drop("mpg", "hp")$collect() LazyFrame_drop = function(..., strict = TRUE) { cols = unpack_list(..., .context = "in $drop():") |> unlist() @@ -1146,7 +1146,7 @@ LazyFrame_drop = function(..., strict = TRUE) { #' @description Reverse the LazyFrame (the last row becomes the first one, etc.). #' @keywords LazyFrame #' @return LazyFrame -#' @examples pl$LazyFrame(mtcars)$reverse()$collect() +#' @examples as_polars_lf(mtcars)$reverse()$collect() LazyFrame_reverse = use_extendr_wrapper #' @title Slice @@ -1154,8 +1154,8 @@ LazyFrame_reverse = use_extendr_wrapper #' @inheritParams DataFrame_slice #' @return A [LazyFrame][LazyFrame_class] #' @examples -#' pl$LazyFrame(mtcars)$slice(2, 4)$collect() -#' pl$LazyFrame(mtcars)$slice(30)$collect() +#' as_polars_lf(mtcars)$slice(2, 4)$collect() +#' as_polars_lf(mtcars)$slice(30)$collect() #' mtcars[2:6, ] LazyFrame_slice = function(offset, length = NULL) { unwrap(.pr$LazyFrame$slice(self, offset, length), "in $slice():") @@ -1696,11 +1696,11 @@ LazyFrame_rename = function(...) { #' #' @examples #' # fetch 3 rows -#' pl$LazyFrame(iris)$fetch(3) +#' as_polars_lf(iris)$fetch(3) #' #' # this fetch-query returns 4 rows, because we started with 3 and appended one #' # row in the query (see section 'Details') -#' pl$LazyFrame(iris)$ +#' as_polars_lf(iris)$ #' select(pl$col("Species")$append("flora gigantica, alien"))$ #' fetch(3) LazyFrame_fetch = function( @@ -1780,7 +1780,7 @@ LazyFrame_fetch = function( #' ## Use $profile() to compare two queries #' #' # -1- map each Species-group with native polars, takes ~120us only -#' pl$LazyFrame(iris)$ +#' as_polars_lf(iris)$ #' sort("Sepal.Length")$ #' group_by("Species", maintain_order = TRUE)$ #' agg(pl$col(pl$Float64)$first() + 5)$ @@ -1794,7 +1794,7 @@ LazyFrame_fetch = function( #' s$to_r()[1] + 5 #' } #' -#' pl$LazyFrame(iris)$ +#' as_polars_lf(iris)$ #' sort("Sepal.Length")$ #' group_by("Species", maintain_order = TRUE)$ #' agg(pl$col(pl$Float64)$map_elements(r_func))$ @@ -1905,7 +1905,7 @@ LazyFrame_explode = function(...) { #' #' @return A LazyFrame #' @examples -#' df1 = pl$LazyFrame(iris) +#' df1 = as_polars_lf(iris) #' #' # Make a function to take a LazyFrame, add an attribute, and return a LazyFrame #' give_attr = function(data) { @@ -1923,7 +1923,7 @@ LazyFrame_explode = function(...) { #' attr(data, "created_on") = "2024-01-29" #' data #' } -#' df1 = pl$LazyFrame(iris) +#' df1 = as_polars_lf(iris) #' df2 = give_attr(df1) #' #' # now, the original LazyFrame doesn't get this attribute diff --git a/R/polars_options.R b/R/polars_options.R index 861f61ce8..c1899b16d 100644 --- a/R/polars_options.R +++ b/R/polars_options.R @@ -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) { diff --git a/R/rbackground.R b/R/rbackground.R index a116d5ab1..369c33a56 100644 --- a/R/rbackground.R +++ b/R/rbackground.R @@ -66,7 +66,7 @@ print.RPolarsRThreadHandle = function(x, ...) as.character(x) |> cat("\n") #' Sys.sleep(.1) #' x * 0.43 #' }, in_background = TRUE)$alias("kml") -#' handle = pl$LazyFrame(mtcars)$with_columns(prexpr)$collect_in_background() +#' handle = as_polars_lf(mtcars)$with_columns(prexpr)$collect_in_background() #' if (!handle$is_finished()) print("not done yet") #' df = handle$join() # get result #' df diff --git a/R/s3-methods.R b/R/s3-methods.R index 0d2a868b3..ecd1e5355 100644 --- a/R/s3-methods.R +++ b/R/s3-methods.R @@ -16,7 +16,7 @@ #' [`$filter()`][DataFrame_filter], #' [`$filter()`][LazyFrame_filter] #' @examples -#' df = pl$DataFrame(data.frame(a = 1:3, b = letters[1:3])) +#' df = as_polars_df(data.frame(a = 1:3, b = letters[1:3])) #' lf = df$lazy() #' #' # Select a row @@ -496,7 +496,7 @@ c.RPolarsSeries = \(x, ...) { #' @export #' @rdname S3_na.omit #' @examples -#' df = pl$DataFrame(data.frame(a = c(NA, 2:10), b = c(1, NA, 3:10)))$lazy() +#' df = as_polars_df(data.frame(a = c(NA, 2:10), b = c(1, NA, 3:10)))$lazy() #' na.omit(df) #' na.omit(df, subset = "a") #' na.omit(df, subset = c("a", "b")) diff --git a/R/sql.R b/R/sql.R index 83639a326..b74c396ad 100644 --- a/R/sql.R +++ b/R/sql.R @@ -100,8 +100,8 @@ SQLContext_register = function(name, frame) { #' @examplesIf polars_info()$features$sql #' ctx = pl$SQLContext() #' r_df = mtcars -#' pl_df = pl$DataFrame(mtcars) -#' pl_lf = pl$LazyFrame(mtcars) +#' pl_df = as_polars_df(mtcars) +#' pl_lf = as_polars_lf(mtcars) #' #' ctx$register_many(r_df = r_df, pl_df = pl_df, pl_lf = pl_lf) #' diff --git a/altdoc/reference_home.Rmd b/altdoc/reference_home.Rmd index 6cf055242..4309d23e0 100644 --- a/altdoc/reference_home.Rmd +++ b/altdoc/reference_home.Rmd @@ -56,7 +56,7 @@ you can only apply expressions that return either the same number of values or a single value that will be duplicated on all rows: ```{r} -test = pl$DataFrame(mtcars) +test = as_polars_df(mtcars) ``` ```{r} diff --git a/man/DataFrame_clone.Rd b/man/DataFrame_clone.Rd index 661a6be91..b0f16d82b 100644 --- a/man/DataFrame_clone.Rd +++ b/man/DataFrame_clone.Rd @@ -16,7 +16,7 @@ immutable. Any modification of a \code{DataFrame} should lead to a clone anyways but this can be useful when dealing with attributes (see examples). } \examples{ -df1 = pl$DataFrame(iris) +df1 = as_polars_df(iris) # Make a function to take a DataFrame, add an attribute, and return a DataFrame give_attr = function(data) { @@ -34,7 +34,7 @@ give_attr = function(data) { attr(data, "created_on") = "2024-01-29" data } -df1 = pl$DataFrame(iris) +df1 = as_polars_df(iris) df2 = give_attr(df1) # now, the original DataFrame doesn't get this attribute diff --git a/man/DataFrame_describe.Rd b/man/DataFrame_describe.Rd index b3dd4dc0e..537f58758 100644 --- a/man/DataFrame_describe.Rd +++ b/man/DataFrame_describe.Rd @@ -22,7 +22,7 @@ values, the mean, standard deviation, min, max, median and the percentiles specified in the argument \code{percentiles}. } \examples{ -pl$DataFrame(iris)$describe() +as_polars_df(iris)$describe() # string, date, boolean columns are also supported: df = pl$DataFrame( diff --git a/man/DataFrame_drop.Rd b/man/DataFrame_drop.Rd index f24b4f7c5..14b80221e 100644 --- a/man/DataFrame_drop.Rd +++ b/man/DataFrame_drop.Rd @@ -19,8 +19,8 @@ DataFrame Drop columns of a DataFrame } \examples{ -pl$DataFrame(mtcars)$drop(c("mpg", "hp")) +as_polars_df(mtcars)$drop(c("mpg", "hp")) # equivalent -pl$DataFrame(mtcars)$drop("mpg", "hp") +as_polars_df(mtcars)$drop("mpg", "hp") } diff --git a/man/DataFrame_drop_in_place.Rd b/man/DataFrame_drop_in_place.Rd index 5c242dda2..013c400eb 100644 --- a/man/DataFrame_drop_in_place.Rd +++ b/man/DataFrame_drop_in_place.Rd @@ -16,7 +16,7 @@ Series Drop a single column in-place and return the dropped column. } \examples{ -dat = pl$DataFrame(iris) +dat = as_polars_df(iris) x = dat$drop_in_place("Species") x dat$columns diff --git a/man/DataFrame_drop_nulls.Rd b/man/DataFrame_drop_nulls.Rd index 4cdde8770..243e00c5d 100644 --- a/man/DataFrame_drop_nulls.Rd +++ b/man/DataFrame_drop_nulls.Rd @@ -20,7 +20,7 @@ Drop all rows that contain nulls (which correspond to \code{NA} in R). 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 diff --git a/man/DataFrame_dtype_strings.Rd b/man/DataFrame_dtype_strings.Rd index 03e7ba4ef..235e628a8 100644 --- a/man/DataFrame_dtype_strings.Rd +++ b/man/DataFrame_dtype_strings.Rd @@ -15,6 +15,6 @@ available types with \code{names(pl$dtypes)}. The data type of each column is al shown when printing the DataFrame. } \examples{ -pl$DataFrame(iris)$dtype_strings() +as_polars_df(iris)$dtype_strings() } \keyword{DataFrame} diff --git a/man/DataFrame_equals.Rd b/man/DataFrame_equals.Rd index 41ea3651c..6c7ee82ff 100644 --- a/man/DataFrame_equals.Rd +++ b/man/DataFrame_equals.Rd @@ -16,9 +16,9 @@ A logical value Check if two DataFrames are equal. } \examples{ -dat1 = pl$DataFrame(iris) -dat2 = pl$DataFrame(iris) -dat3 = pl$DataFrame(mtcars) +dat1 = as_polars_df(iris) +dat2 = as_polars_df(iris) +dat3 = as_polars_df(mtcars) dat1$equals(dat2) dat1$equals(dat3) } diff --git a/man/DataFrame_estimated_size.Rd b/man/DataFrame_estimated_size.Rd index abdf64e45..38fc58e28 100644 --- a/man/DataFrame_estimated_size.Rd +++ b/man/DataFrame_estimated_size.Rd @@ -17,6 +17,6 @@ Return an estimation of the total (heap) allocated size of the DataFrame. } \examples{ -pl$DataFrame(mtcars)$estimated_size() +as_polars_df(mtcars)$estimated_size() } \keyword{DataFrame} diff --git a/man/DataFrame_filter.Rd b/man/DataFrame_filter.Rd index a785cf491..434455df7 100644 --- a/man/DataFrame_filter.Rd +++ b/man/DataFrame_filter.Rd @@ -21,7 +21,7 @@ This is equivalent to \code{\link[dplyr:filter]{dplyr::filter()}}. Rows where the condition returns \code{NA} are dropped. } \examples{ -df = pl$DataFrame(iris) +df = as_polars_df(iris) df$filter(pl$col("Sepal.Length") > 5) @@ -32,7 +32,7 @@ df$filter(pl$col("Sepal.Length") > 5, pl$col("Petal.Width") < 1) # rows where condition is NA are dropped iris2 = iris iris2[c(1, 3, 5), "Species"] = NA -df = pl$DataFrame(iris2) +df = as_polars_df(iris2) df$filter(pl$col("Species") == "setosa") } diff --git a/man/DataFrame_first.Rd b/man/DataFrame_first.Rd index d28997d03..2c7edf241 100644 --- a/man/DataFrame_first.Rd +++ b/man/DataFrame_first.Rd @@ -13,6 +13,6 @@ A DataFrame with one row. Get the first row of the DataFrame. } \examples{ -pl$DataFrame(mtcars)$first() +as_polars_df(mtcars)$first() } \keyword{DataFrame} diff --git a/man/DataFrame_get_column.Rd b/man/DataFrame_get_column.Rd index 9418a7648..c6c01657e 100644 --- a/man/DataFrame_get_column.Rd +++ b/man/DataFrame_get_column.Rd @@ -16,7 +16,7 @@ Series Extract a DataFrame column as a Polars series. } \examples{ -df = pl$DataFrame(iris[1:2, ]) +df = as_polars_df(iris[1:2, ]) df$get_column("Species") } \keyword{DataFrame} diff --git a/man/DataFrame_glimpse.Rd b/man/DataFrame_glimpse.Rd index 60126570c..61ad72229 100644 --- a/man/DataFrame_glimpse.Rd +++ b/man/DataFrame_glimpse.Rd @@ -31,5 +31,5 @@ cleanly. Each line shows the column name, the data type, and the first few values. } \examples{ -pl$DataFrame(iris)$glimpse() +as_polars_df(iris)$glimpse() } diff --git a/man/DataFrame_last.Rd b/man/DataFrame_last.Rd index 6057763db..82a7ed264 100644 --- a/man/DataFrame_last.Rd +++ b/man/DataFrame_last.Rd @@ -13,6 +13,6 @@ A DataFrame with one row. Get the last row of the DataFrame. } \examples{ -pl$DataFrame(mtcars)$last() +as_polars_df(mtcars)$last() } \keyword{DataFrame} diff --git a/man/DataFrame_lazy.Rd b/man/DataFrame_lazy.Rd index d58fc9b49..bca6cdb80 100644 --- a/man/DataFrame_lazy.Rd +++ b/man/DataFrame_lazy.Rd @@ -14,7 +14,7 @@ A LazyFrame Start a new lazy query from a DataFrame. } \examples{ -pl$DataFrame(iris)$lazy() +as_polars_df(iris)$lazy() } \keyword{DataFrame} \keyword{LazyFrame_new} diff --git a/man/DataFrame_max.Rd b/man/DataFrame_max.Rd index 9f38ab0bf..8aa2b5e93 100644 --- a/man/DataFrame_max.Rd +++ b/man/DataFrame_max.Rd @@ -13,6 +13,6 @@ A DataFrame with one row. Aggregate the columns in the DataFrame to their maximum value. } \examples{ -pl$DataFrame(mtcars)$max() +as_polars_df(mtcars)$max() } \keyword{DataFrame} diff --git a/man/DataFrame_mean.Rd b/man/DataFrame_mean.Rd index ff21ca28d..848df3c2d 100644 --- a/man/DataFrame_mean.Rd +++ b/man/DataFrame_mean.Rd @@ -13,6 +13,6 @@ A DataFrame with one row. Aggregate the columns in the DataFrame to their mean value. } \examples{ -pl$DataFrame(mtcars)$mean() +as_polars_df(mtcars)$mean() } \keyword{DataFrame} diff --git a/man/DataFrame_median.Rd b/man/DataFrame_median.Rd index 7a9336056..19413a9c3 100644 --- a/man/DataFrame_median.Rd +++ b/man/DataFrame_median.Rd @@ -13,6 +13,6 @@ A DataFrame with one row. Aggregate the columns in the DataFrame to their median value. } \examples{ -pl$DataFrame(mtcars)$median() +as_polars_df(mtcars)$median() } \keyword{DataFrame} diff --git a/man/DataFrame_min.Rd b/man/DataFrame_min.Rd index a23ab0871..f9793131a 100644 --- a/man/DataFrame_min.Rd +++ b/man/DataFrame_min.Rd @@ -13,6 +13,6 @@ A DataFrame with one row. Aggregate the columns in the DataFrame to their minimum value. } \examples{ -pl$DataFrame(mtcars)$min() +as_polars_df(mtcars)$min() } \keyword{DataFrame} diff --git a/man/DataFrame_quantile.Rd b/man/DataFrame_quantile.Rd index 6e7924a96..f699c10ae 100644 --- a/man/DataFrame_quantile.Rd +++ b/man/DataFrame_quantile.Rd @@ -20,6 +20,6 @@ Aggregate the columns in the DataFrame to a unique quantile value. Use \verb{$describe()} to specify several quantiles. } \examples{ -pl$DataFrame(mtcars)$quantile(.4) +as_polars_df(mtcars)$quantile(.4) } \keyword{DataFrame} diff --git a/man/DataFrame_reverse.Rd b/man/DataFrame_reverse.Rd index 36d44b271..daa32a200 100644 --- a/man/DataFrame_reverse.Rd +++ b/man/DataFrame_reverse.Rd @@ -13,5 +13,5 @@ DataFrame Reverse the DataFrame (the last row becomes the first one, etc.). } \examples{ -pl$DataFrame(mtcars)$reverse() +as_polars_df(mtcars)$reverse() } diff --git a/man/DataFrame_sample.Rd b/man/DataFrame_sample.Rd index 95dd7b579..15db33848 100644 --- a/man/DataFrame_sample.Rd +++ b/man/DataFrame_sample.Rd @@ -37,7 +37,7 @@ DataFrame Take a sample of rows from a DataFrame } \examples{ -df = pl$DataFrame(iris) +df = as_polars_df(iris) df$sample(n = 20) df$sample(fraction = 0.1) } diff --git a/man/DataFrame_select.Rd b/man/DataFrame_select.Rd index 9f4b4baed..bc9bd609a 100644 --- a/man/DataFrame_select.Rd +++ b/man/DataFrame_select.Rd @@ -20,7 +20,7 @@ Similar to \code{dplyr::mutate()}. However, it discards unmentioned columns (like \code{.()} in \code{data.table}). } \examples{ -pl$DataFrame(iris)$select( +as_polars_df(iris)$select( pl$col("Sepal.Length")$abs()$alias("abs_SL"), (pl$col("Sepal.Length") + 2)$alias("add_2_SL") ) diff --git a/man/DataFrame_select_seq.Rd b/man/DataFrame_select_seq.Rd index d37b75c9c..5619b423b 100644 --- a/man/DataFrame_select_seq.Rd +++ b/man/DataFrame_select_seq.Rd @@ -23,7 +23,7 @@ when the work per expression is cheap. Otherwise, \verb{$select()} should be preferred. } \examples{ -pl$DataFrame(iris)$select_seq( +as_polars_df(iris)$select_seq( pl$col("Sepal.Length")$abs()$alias("abs_SL"), (pl$col("Sepal.Length") + 2)$alias("add_2_SL") ) diff --git a/man/DataFrame_slice.Rd b/man/DataFrame_slice.Rd index adbafd073..2d2c08259 100644 --- a/man/DataFrame_slice.Rd +++ b/man/DataFrame_slice.Rd @@ -21,7 +21,7 @@ Get a slice of the DataFrame. } \examples{ # skip the first 2 rows and take the 4 following rows -pl$DataFrame(mtcars)$slice(2, 4) +as_polars_df(mtcars)$slice(2, 4) # this is equivalent to: mtcars[3:6, ] diff --git a/man/DataFrame_std.Rd b/man/DataFrame_std.Rd index 816e83210..d86aedda4 100644 --- a/man/DataFrame_std.Rd +++ b/man/DataFrame_std.Rd @@ -18,6 +18,6 @@ Aggregate the columns of this DataFrame to their standard deviation values. } \examples{ -pl$DataFrame(mtcars)$std() +as_polars_df(mtcars)$std() } \keyword{DataFrame} diff --git a/man/DataFrame_sum.Rd b/man/DataFrame_sum.Rd index d6018b971..ba771272a 100644 --- a/man/DataFrame_sum.Rd +++ b/man/DataFrame_sum.Rd @@ -13,6 +13,6 @@ A DataFrame with one row. Aggregate the columns of this DataFrame to their sum values. } \examples{ -pl$DataFrame(mtcars)$sum() +as_polars_df(mtcars)$sum() } \keyword{DataFrame} diff --git a/man/DataFrame_to_data_frame.Rd b/man/DataFrame_to_data_frame.Rd index 04401a24c..a166999f7 100644 --- a/man/DataFrame_to_data_frame.Rd +++ b/man/DataFrame_to_data_frame.Rd @@ -72,7 +72,7 @@ withr::with_timezone( } \examples{ -df = pl$DataFrame(iris[1:3, ]) +df = as_polars_df(iris[1:3, ]) df$to_data_frame() } \keyword{DataFrame} diff --git a/man/DataFrame_to_list.Rd b/man/DataFrame_to_list.Rd index 766d7d1d0..35f22b40e 100644 --- a/man/DataFrame_to_list.Rd +++ b/man/DataFrame_to_list.Rd @@ -82,7 +82,7 @@ withr::with_timezone( } \examples{ -pl$DataFrame(iris)$to_list() +as_polars_df(iris)$to_list() } \seealso{ \itemize{ diff --git a/man/DataFrame_to_series.Rd b/man/DataFrame_to_series.Rd index 4a6f269f0..b1331630d 100644 --- a/man/DataFrame_to_series.Rd +++ b/man/DataFrame_to_series.Rd @@ -20,7 +20,7 @@ index doesn't exist in the DataFrame. Keep in mind that Polars is 0-indexed so "0" is the first column. } \examples{ -df = pl$DataFrame(iris[1:10, ]) +df = as_polars_df(iris[1:10, ]) # default is to extract the first column df$to_series() diff --git a/man/DataFrame_transpose.Rd b/man/DataFrame_transpose.Rd index 1196a56c1..68299d74b 100644 --- a/man/DataFrame_transpose.Rd +++ b/man/DataFrame_transpose.Rd @@ -37,11 +37,11 @@ Polars transpose is currently eager only, likely because it is not trivial to de \examples{ # simple use-case -pl$DataFrame(mtcars)$transpose(include_header = TRUE, column_names = rownames(mtcars)) +as_polars_df(mtcars)$transpose(include_header = TRUE, column_names = rownames(mtcars)) # All rows must have one shared supertype, recast Categorical to String which is a supertype # of f64, and then dataset "Iris" can be transposed -pl$DataFrame(iris)$with_columns(pl$col("Species")$cast(pl$String))$transpose() +as_polars_df(iris)$with_columns(pl$col("Species")$cast(pl$String))$transpose() } \keyword{DataFrame} diff --git a/man/DataFrame_var.Rd b/man/DataFrame_var.Rd index f9d9320d1..e09b39e75 100644 --- a/man/DataFrame_var.Rd +++ b/man/DataFrame_var.Rd @@ -17,6 +17,6 @@ A DataFrame with one row. Aggregate the columns of this DataFrame to their variance values. } \examples{ -pl$DataFrame(mtcars)$var() +as_polars_df(mtcars)$var() } \keyword{DataFrame} diff --git a/man/DataFrame_with_columns.Rd b/man/DataFrame_with_columns.Rd index 3aef9b959..7fbcc6801 100644 --- a/man/DataFrame_with_columns.Rd +++ b/man/DataFrame_with_columns.Rd @@ -20,7 +20,7 @@ the equivalent of \code{dplyr::mutate()} as it keeps unmentioned columns (unlike \verb{$select()}). } \examples{ -pl$DataFrame(iris)$with_columns( +as_polars_df(iris)$with_columns( pl$col("Sepal.Length")$abs()$alias("abs_SL"), (pl$col("Sepal.Length") + 2)$alias("add_2_SL") ) @@ -30,9 +30,9 @@ l_expr = list( pl$col("Sepal.Length")$abs()$alias("abs_SL"), (pl$col("Sepal.Length") + 2)$alias("add_2_SL") ) -pl$DataFrame(iris)$with_columns(l_expr) +as_polars_df(iris)$with_columns(l_expr) -pl$DataFrame(iris)$with_columns( +as_polars_df(iris)$with_columns( pl$col("Sepal.Length")$abs(), # not named expr will keep name "Sepal.Length" SW_add_2 = (pl$col("Sepal.Width") + 2) ) diff --git a/man/DataFrame_with_columns_seq.Rd b/man/DataFrame_with_columns_seq.Rd index 2cce8b035..edfce43f2 100644 --- a/man/DataFrame_with_columns_seq.Rd +++ b/man/DataFrame_with_columns_seq.Rd @@ -23,7 +23,7 @@ when the work per expression is cheap. Otherwise, \verb{$with_columns()} should preferred. } \examples{ -pl$DataFrame(iris)$with_columns_seq( +as_polars_df(iris)$with_columns_seq( pl$col("Sepal.Length")$abs()$alias("abs_SL"), (pl$col("Sepal.Length") + 2)$alias("add_2_SL") ) @@ -33,9 +33,9 @@ l_expr = list( pl$col("Sepal.Length")$abs()$alias("abs_SL"), (pl$col("Sepal.Length") + 2)$alias("add_2_SL") ) -pl$DataFrame(iris)$with_columns_seq(l_expr) +as_polars_df(iris)$with_columns_seq(l_expr) -pl$DataFrame(iris)$with_columns_seq( +as_polars_df(iris)$with_columns_seq( pl$col("Sepal.Length")$abs(), # not named expr will keep name "Sepal.Length" SW_add_2 = (pl$col("Sepal.Width") + 2) ) diff --git a/man/DataFrame_with_row_index.Rd b/man/DataFrame_with_row_index.Rd index 139afca89..25991349d 100644 --- a/man/DataFrame_with_row_index.Rd +++ b/man/DataFrame_with_row_index.Rd @@ -18,7 +18,7 @@ A new \code{DataFrame} object with a counter column in front Add a new column at index 0 that counts the rows } \examples{ -df = pl$DataFrame(mtcars) +df = as_polars_df(mtcars) # by default, the index starts at 0 (to mimic the behavior of Python Polars) df$with_row_index("idx") diff --git a/man/ExprName_prefix.Rd b/man/ExprName_prefix.Rd index 793d9c1f9..363747daa 100644 --- a/man/ExprName_prefix.Rd +++ b/man/ExprName_prefix.Rd @@ -16,7 +16,7 @@ Expr Add a prefix to a column name } \examples{ -dat = pl$DataFrame(mtcars) +dat = as_polars_df(mtcars) dat$select( pl$col("mpg"), diff --git a/man/ExprName_suffix.Rd b/man/ExprName_suffix.Rd index a1acafe66..39adeddf4 100644 --- a/man/ExprName_suffix.Rd +++ b/man/ExprName_suffix.Rd @@ -16,7 +16,7 @@ Expr Add a suffix to a column name } \examples{ -dat = pl$DataFrame(mtcars) +dat = as_polars_df(mtcars) dat$select( pl$col("mpg"), diff --git a/man/Expr_approx_n_unique.Rd b/man/Expr_approx_n_unique.Rd index 85c845ada..43c44fa75 100644 --- a/man/Expr_approx_n_unique.Rd +++ b/man/Expr_approx_n_unique.Rd @@ -13,6 +13,6 @@ Expr This is done using the HyperLogLog++ algorithm for cardinality estimation. } \examples{ -pl$DataFrame(iris[, 4:5])$ +as_polars_df(iris[, 4:5])$ with_columns(count = pl$col("Species")$approx_n_unique()) } diff --git a/man/Expr_exclude.Rd b/man/Expr_exclude.Rd index b4a094791..6a320f740 100644 --- a/man/Expr_exclude.Rd +++ b/man/Expr_exclude.Rd @@ -25,7 +25,7 @@ Exclude certain columns from selection \examples{ # make DataFrame -df = pl$DataFrame(iris) +df = as_polars_df(iris) # by name(s) df$select(pl$all()$exclude("Species")) diff --git a/man/Expr_hash.Rd b/man/Expr_hash.Rd index 6b017a4ec..5fcf37ae2 100644 --- a/man/Expr_hash.Rd +++ b/man/Expr_hash.Rd @@ -21,6 +21,6 @@ Expr The hash value is of type \code{UInt64}. } \examples{ -df = pl$DataFrame(iris[1:3, c(1, 2)]) +df = as_polars_df(iris[1:3, c(1, 2)]) df$with_columns(pl$all()$hash(1234)$name$suffix("_hash")) } diff --git a/man/Expr_is_duplicated.Rd b/man/Expr_is_duplicated.Rd index cf0bc51f9..513c125a6 100644 --- a/man/Expr_is_duplicated.Rd +++ b/man/Expr_is_duplicated.Rd @@ -13,6 +13,6 @@ Expr This is syntactic sugar for \verb{$is_unique()$not()}. } \examples{ -pl$DataFrame(head(mtcars[, 1:2]))$ +as_polars_df(head(mtcars[, 1:2]))$ with_columns(is_duplicated = pl$col("mpg")$is_duplicated()) } diff --git a/man/Expr_is_first_distinct.Rd b/man/Expr_is_first_distinct.Rd index 2d8349060..1eedf5258 100644 --- a/man/Expr_is_first_distinct.Rd +++ b/man/Expr_is_first_distinct.Rd @@ -13,6 +13,6 @@ Expr Check whether each value is the first occurrence } \examples{ -pl$DataFrame(head(mtcars[, 1:2]))$ +as_polars_df(head(mtcars[, 1:2]))$ with_columns(is_ufirst = pl$col("mpg")$is_first_distinct()) } diff --git a/man/Expr_is_last_distinct.Rd b/man/Expr_is_last_distinct.Rd index b13d72af8..aed105f4f 100644 --- a/man/Expr_is_last_distinct.Rd +++ b/man/Expr_is_last_distinct.Rd @@ -13,6 +13,6 @@ Expr Check whether each value is the last occurrence } \examples{ -pl$DataFrame(head(mtcars[, 1:2]))$ +as_polars_df(head(mtcars[, 1:2]))$ with_columns(is_ulast = pl$col("mpg")$is_last_distinct()) } diff --git a/man/Expr_is_unique.Rd b/man/Expr_is_unique.Rd index 7cb252f35..4f0adcf26 100644 --- a/man/Expr_is_unique.Rd +++ b/man/Expr_is_unique.Rd @@ -13,6 +13,6 @@ Expr Check whether each value is unique } \examples{ -pl$DataFrame(head(mtcars[, 1:2]))$ +as_polars_df(head(mtcars[, 1:2]))$ with_columns(is_unique = pl$col("mpg")$is_unique()) } diff --git a/man/Expr_map_batches.Rd b/man/Expr_map_batches.Rd index 6e5460abb..67fefa85a 100644 --- a/man/Expr_map_batches.Rd +++ b/man/Expr_map_batches.Rd @@ -54,7 +54,7 @@ to global variables. Use \code{options(polars.rpool_cap = 4)} and \code{polars_options()$rpool_cap} to set and view number of parallel R sessions. } \examples{ -pl$DataFrame(iris)$ +as_polars_df(iris)$ select( pl$col("Sepal.Length")$map_batches(\(x) { paste("cheese", as.character(x$to_vector())) diff --git a/man/Expr_map_elements.Rd b/man/Expr_map_elements.Rd index e8a3844f8..6f7a91e52 100644 --- a/man/Expr_map_elements.Rd +++ b/man/Expr_map_elements.Rd @@ -77,7 +77,7 @@ achieve the best performance and avoid using \verb{$map_elements()}. # get the first two values of each variable and store them in a list e_sum = pl$all()$map_elements(\(s) sum(s$to_r()))$name$suffix("_sum") e_head = pl$all()$map_elements(\(s) head(s$to_r(), 2))$name$suffix("_head") -pl$DataFrame(iris)$group_by("Species")$agg(e_sum, e_head) +as_polars_df(iris)$group_by("Species")$agg(e_sum, e_head) # apply a function on each value (should be avoided): here the input is an R # value of length 1 @@ -93,7 +93,7 @@ e_add10 = my_selection$map_elements(\(x) { e_letter = my_selection$map_elements(\(x) { letters[ceiling(x)] }, return_type = pl$dtypes$String)$name$suffix("_letter") -pl$DataFrame(iris)$select(e_add10, e_letter) +as_polars_df(iris)$select(e_add10, e_letter) # Small benchmark -------------------------------- @@ -130,7 +130,7 @@ system.time({ # use apply over each Species-group in each column equal to 12 sequential # runs ~1.2 sec. system.time({ - pl$LazyFrame(iris)$group_by("Species")$agg( + as_polars_lf(iris)$group_by("Species")$agg( pl$all()$map_elements(\(s) { Sys.sleep(.1) s$sum() @@ -146,7 +146,7 @@ options(polars.rpool_cap = 4) polars_options()$rpool_cap system.time({ - pl$LazyFrame(iris)$group_by("Species")$agg( + as_polars_lf(iris)$group_by("Species")$agg( pl$all()$map_elements(\(s) { Sys.sleep(.1) s$sum() @@ -157,7 +157,7 @@ system.time({ # second run in parallel: this reuses R processes in "polars global_rpool". polars_options()$rpool_cap system.time({ - pl$LazyFrame(iris)$group_by("Species")$agg( + as_polars_lf(iris)$group_by("Species")$agg( pl$all()$map_elements(\(s) { Sys.sleep(.1) s$sum() diff --git a/man/Expr_n_unique.Rd b/man/Expr_n_unique.Rd index 1b4da6658..5e9b9a99b 100644 --- a/man/Expr_n_unique.Rd +++ b/man/Expr_n_unique.Rd @@ -13,5 +13,5 @@ Expr Count number of unique values } \examples{ -pl$DataFrame(iris[, 4:5])$with_columns(count = pl$col("Species")$n_unique()) +as_polars_df(iris[, 4:5])$with_columns(count = pl$col("Species")$n_unique()) } diff --git a/man/Expr_slice.Rd b/man/Expr_slice.Rd index 1f5bd0cfe..744751532 100644 --- a/man/Expr_slice.Rd +++ b/man/Expr_slice.Rd @@ -37,5 +37,5 @@ pl$DataFrame(list(a = 0:100))$select( ) # recycling -pl$DataFrame(mtcars)$with_columns(pl$col("mpg")$slice(0, 1)$first()) +as_polars_df(mtcars)$with_columns(pl$col("mpg")$slice(0, 1)$first()) } diff --git a/man/Expr_unique.Rd b/man/Expr_unique.Rd index b525c0fa2..ae181566d 100644 --- a/man/Expr_unique.Rd +++ b/man/Expr_unique.Rd @@ -17,5 +17,5 @@ Expr Get unique values } \examples{ -pl$DataFrame(iris)$select(pl$col("Species")$unique()) +as_polars_df(iris)$select(pl$col("Species")$unique()) } diff --git a/man/Expr_unique_counts.Rd b/man/Expr_unique_counts.Rd index 7d8e15b27..0548f0fb0 100644 --- a/man/Expr_unique_counts.Rd +++ b/man/Expr_unique_counts.Rd @@ -15,5 +15,5 @@ differs from \verb{$value_counts()} in that it does not return the values, only the counts and it might be faster. } \examples{ -pl$DataFrame(iris)$select(pl$col("Species")$unique_counts()) +as_polars_df(iris)$select(pl$col("Species")$unique_counts()) } diff --git a/man/Expr_value_counts.Rd b/man/Expr_value_counts.Rd index 2e3d7f7f9..674673fe9 100644 --- a/man/Expr_value_counts.Rd +++ b/man/Expr_value_counts.Rd @@ -27,7 +27,7 @@ Expr Count all unique values and create a struct mapping value to count. } \examples{ -df = pl$DataFrame(iris) +df = as_polars_df(iris) df$select(pl$col("Species")$value_counts())$unnest() df$select(pl$col("Species")$value_counts(normalize = TRUE))$unnest() } diff --git a/man/GroupBy_quantile.Rd b/man/GroupBy_quantile.Rd index d08f81f7e..d3bed3d92 100644 --- a/man/GroupBy_quantile.Rd +++ b/man/GroupBy_quantile.Rd @@ -18,6 +18,6 @@ GroupBy Aggregate the columns in the DataFrame to their quantile value. } \examples{ -pl$DataFrame(mtcars)$lazy()$quantile(.4)$collect() +as_polars_df(mtcars)$lazy()$quantile(.4)$collect() } \keyword{GroupBy} diff --git a/man/GroupBy_shift.Rd b/man/GroupBy_shift.Rd index 1098bfcc3..3f181bfc0 100644 --- a/man/GroupBy_shift.Rd +++ b/man/GroupBy_shift.Rd @@ -20,5 +20,5 @@ GroupBy Shift the values by a given period } \examples{ -pl$DataFrame(mtcars)$group_by("cyl")$shift(2) +as_polars_df(mtcars)$group_by("cyl")$shift(2) } diff --git a/man/GroupBy_ungroup.Rd b/man/GroupBy_ungroup.Rd index c6230167f..4cd90fae1 100644 --- a/man/GroupBy_ungroup.Rd +++ b/man/GroupBy_ungroup.Rd @@ -13,7 +13,7 @@ GroupBy_ungroup() Revert the group by operation. } \examples{ -gb = pl$DataFrame(mtcars)$group_by("cyl") +gb = as_polars_df(mtcars)$group_by("cyl") gb gb$ungroup() diff --git a/man/IO_read_parquet.Rd b/man/IO_read_parquet.Rd index 1c0da7c10..97f2519f4 100644 --- a/man/IO_read_parquet.Rd +++ b/man/IO_read_parquet.Rd @@ -139,13 +139,13 @@ either of the following methods: \dontshow{if (requireNamespace("withr", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # Write a Parquet file than we can then import as DataFrame temp_file = withr::local_tempfile(fileext = ".parquet") -pl$DataFrame(mtcars)$write_parquet(temp_file) +as_polars_df(mtcars)$write_parquet(temp_file) pl$read_parquet(temp_file) # Write a hive-style partitioned parquet dataset temp_dir = withr::local_tempdir() -pl$DataFrame(mtcars)$write_parquet(temp_dir, partition_by = c("cyl", "gear")) +as_polars_df(mtcars)$write_parquet(temp_dir, partition_by = c("cyl", "gear")) list.files(temp_dir, recursive = TRUE) # If the path is a folder, Polars automatically tries to detect partitions diff --git a/man/IO_scan_parquet.Rd b/man/IO_scan_parquet.Rd index 202993bed..b8517db4c 100644 --- a/man/IO_scan_parquet.Rd +++ b/man/IO_scan_parquet.Rd @@ -139,13 +139,13 @@ either of the following methods: \dontshow{if (requireNamespace("withr", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # Write a Parquet file than we can then import as DataFrame temp_file = withr::local_tempfile(fileext = ".parquet") -pl$DataFrame(mtcars)$write_parquet(temp_file) +as_polars_df(mtcars)$write_parquet(temp_file) pl$scan_parquet(temp_file)$collect() # Write a hive-style partitioned parquet dataset temp_dir = withr::local_tempdir() -pl$DataFrame(mtcars)$write_parquet(temp_dir, partition_by = c("cyl", "gear")) +as_polars_df(mtcars)$write_parquet(temp_dir, partition_by = c("cyl", "gear")) list.files(temp_dir, recursive = TRUE) # If the path is a folder, Polars automatically tries to detect partitions diff --git a/man/IO_sink_csv.Rd b/man/IO_sink_csv.Rd index e702a5588..6f8be8cb8 100644 --- a/man/IO_sink_csv.Rd +++ b/man/IO_sink_csv.Rd @@ -111,7 +111,7 @@ larger than RAM as it would crash the R session if it was collected into R. \examples{ # sink table 'mtcars' from mem to CSV tmpf = tempfile() -pl$LazyFrame(mtcars)$sink_csv(tmpf) +as_polars_lf(mtcars)$sink_csv(tmpf) # stream a query end-to-end tmpf2 = tempfile() diff --git a/man/IO_sink_ipc.Rd b/man/IO_sink_ipc.Rd index 975acf665..bbde1fc73 100644 --- a/man/IO_sink_ipc.Rd +++ b/man/IO_sink_ipc.Rd @@ -60,7 +60,7 @@ larger than RAM as it would crash the R session if it was collected into R. \examples{ # sink table 'mtcars' from mem to ipc tmpf = tempfile() -pl$LazyFrame(mtcars)$sink_ipc(tmpf) +as_polars_lf(mtcars)$sink_ipc(tmpf) # stream a query end-to-end (not supported yet, https://github.com/pola-rs/polars/issues/1040) # tmpf2 = tempfile() diff --git a/man/IO_sink_ndjson.Rd b/man/IO_sink_ndjson.Rd index 0f076a135..8ae5c7180 100644 --- a/man/IO_sink_ndjson.Rd +++ b/man/IO_sink_ndjson.Rd @@ -54,7 +54,7 @@ larger than RAM as it would crash the R session if it was collected into R. \examples{ # sink table 'mtcars' from mem to JSON tmpf = tempfile(fileext = ".json") -pl$LazyFrame(mtcars)$sink_ndjson(tmpf) +as_polars_lf(mtcars)$sink_ndjson(tmpf) # load parquet directly into a DataFrame / memory pl$scan_ndjson(tmpf)$collect() diff --git a/man/IO_sink_parquet.Rd b/man/IO_sink_parquet.Rd index 47ce53f61..4f013ed7f 100644 --- a/man/IO_sink_parquet.Rd +++ b/man/IO_sink_parquet.Rd @@ -99,7 +99,7 @@ larger than RAM as it would crash the R session if it was collected into R. \examples{ # sink table 'mtcars' from mem to parquet tmpf = tempfile() -pl$LazyFrame(mtcars)$sink_parquet(tmpf) +as_polars_lf(mtcars)$sink_parquet(tmpf) # stream a query end-to-end tmpf2 = tempfile() diff --git a/man/IO_write_csv.Rd b/man/IO_write_csv.Rd index d1268e8c2..862b5dc5f 100644 --- a/man/IO_write_csv.Rd +++ b/man/IO_write_csv.Rd @@ -78,7 +78,7 @@ Invisibly returns the input DataFrame. Write to comma-separated values (CSV) file } \examples{ -dat = pl$DataFrame(mtcars) +dat = as_polars_df(mtcars) destination = tempfile(fileext = ".csv") dat$select(pl$col("drat", "mpg"))$write_csv(destination) diff --git a/man/IO_write_ipc.Rd b/man/IO_write_ipc.Rd index f4a7b61ca..99330e706 100644 --- a/man/IO_write_ipc.Rd +++ b/man/IO_write_ipc.Rd @@ -37,7 +37,7 @@ Invisibly returns the input DataFrame. Write to Arrow IPC file (a.k.a Feather file) } \examples{ -dat = pl$DataFrame(mtcars) +dat = as_polars_df(mtcars) destination = tempfile(fileext = ".arrow") dat$write_ipc(destination) diff --git a/man/IO_write_json.Rd b/man/IO_write_json.Rd index 8c25a42e9..7877d955b 100644 --- a/man/IO_write_json.Rd +++ b/man/IO_write_json.Rd @@ -24,7 +24,7 @@ Write to JSON file } \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) diff --git a/man/IO_write_ndjson.Rd b/man/IO_write_ndjson.Rd index 6beeaf924..dbc80bfbe 100644 --- a/man/IO_write_ndjson.Rd +++ b/man/IO_write_ndjson.Rd @@ -16,7 +16,7 @@ Invisibly returns the input DataFrame. Write to NDJSON file } \examples{ -dat = pl$DataFrame(head(mtcars)) +dat = as_polars_df(head(mtcars)) destination = tempfile() dat$select(pl$col("drat", "mpg"))$write_ndjson(destination) diff --git a/man/IO_write_parquet.Rd b/man/IO_write_parquet.Rd index 22c275b55..d5175dad6 100644 --- a/man/IO_write_parquet.Rd +++ b/man/IO_write_parquet.Rd @@ -78,7 +78,7 @@ Write to parquet file } \examples{ \dontshow{if (requireNamespace("withr", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} -dat = pl$DataFrame(mtcars) +dat = as_polars_df(mtcars) # write data to a single parquet file destination = withr::local_tempfile(fileext = ".parquet") diff --git a/man/LazyFrame_clone.Rd b/man/LazyFrame_clone.Rd index f83b17394..03ef42027 100644 --- a/man/LazyFrame_clone.Rd +++ b/man/LazyFrame_clone.Rd @@ -16,7 +16,7 @@ immutable. Any modification of a \code{LazyFrame} should lead to a clone anyways but this can be useful when dealing with attributes (see examples). } \examples{ -df1 = pl$LazyFrame(iris) +df1 = as_polars_lf(iris) # Make a function to take a LazyFrame, add an attribute, and return a LazyFrame give_attr = function(data) { @@ -34,7 +34,7 @@ give_attr = function(data) { attr(data, "created_on") = "2024-01-29" data } -df1 = pl$LazyFrame(iris) +df1 = as_polars_lf(iris) df2 = give_attr(df1) # now, the original LazyFrame doesn't get this attribute diff --git a/man/LazyFrame_collect.Rd b/man/LazyFrame_collect.Rd index e26b7c47f..10c276f19 100644 --- a/man/LazyFrame_collect.Rd +++ b/man/LazyFrame_collect.Rd @@ -69,7 +69,7 @@ Note: use \verb{$fetch(n)} if you want to run your query on the first \code{n} r This can be a huge time saver in debugging queries. } \examples{ -pl$LazyFrame(iris)$filter(pl$col("Species") == "setosa")$collect() +as_polars_lf(iris)$filter(pl$col("Species") == "setosa")$collect() } \seealso{ \itemize{ diff --git a/man/LazyFrame_collect_in_background.Rd b/man/LazyFrame_collect_in_background.Rd index 35301e92c..345d7d353 100644 --- a/man/LazyFrame_collect_in_background.Rd +++ b/man/LazyFrame_collect_in_background.Rd @@ -37,7 +37,7 @@ expr = pl$col("mpg")$map_batches( )$alias("kml") # return is immediately a handle to another thread. -handle = pl$LazyFrame(mtcars)$with_columns(expr)$collect_in_background() +handle = as_polars_lf(mtcars)$with_columns(expr)$collect_in_background() # ask if query is done if (!handle$is_finished()) print("not done yet") diff --git a/man/LazyFrame_drop.Rd b/man/LazyFrame_drop.Rd index 72540759f..88c9a9c1f 100644 --- a/man/LazyFrame_drop.Rd +++ b/man/LazyFrame_drop.Rd @@ -19,8 +19,8 @@ LazyFrame Drop columns of a LazyFrame } \examples{ -pl$LazyFrame(mtcars)$drop(c("mpg", "hp"))$collect() +as_polars_lf(mtcars)$drop(c("mpg", "hp"))$collect() # equivalent -pl$LazyFrame(mtcars)$drop("mpg", "hp")$collect() +as_polars_lf(mtcars)$drop("mpg", "hp")$collect() } diff --git a/man/LazyFrame_explain.Rd b/man/LazyFrame_explain.Rd index 073c6569c..45132e704 100644 --- a/man/LazyFrame_explain.Rd +++ b/man/LazyFrame_explain.Rd @@ -66,7 +66,7 @@ One classic example is the predicate pushdown, which applies the filter as early as possible (i.e. at the bottom of the plan). } \examples{ -lazy_frame = pl$LazyFrame(iris) +lazy_frame = as_polars_lf(iris) # Prepare your query lazy_query = lazy_frame$sort("Species")$filter(pl$col("Species") != "setosa") diff --git a/man/LazyFrame_fetch.Rd b/man/LazyFrame_fetch.Rd index 07e32954e..73f8f3cef 100644 --- a/man/LazyFrame_fetch.Rd +++ b/man/LazyFrame_fetch.Rd @@ -70,11 +70,11 @@ file influence the final number of rows. } \examples{ # fetch 3 rows -pl$LazyFrame(iris)$fetch(3) +as_polars_lf(iris)$fetch(3) # this fetch-query returns 4 rows, because we started with 3 and appended one # row in the query (see section 'Details') -pl$LazyFrame(iris)$ +as_polars_lf(iris)$ select(pl$col("Species")$append("flora gigantica, alien"))$ fetch(3) } diff --git a/man/LazyFrame_filter.Rd b/man/LazyFrame_filter.Rd index 41cf09c64..82d4b7e3a 100644 --- a/man/LazyFrame_filter.Rd +++ b/man/LazyFrame_filter.Rd @@ -21,7 +21,7 @@ This is equivalent to \code{\link[dplyr:filter]{dplyr::filter()}}. Rows where the condition returns \code{NA} are dropped. } \examples{ -lf = pl$LazyFrame(iris) +lf = as_polars_lf(iris) lf$filter(pl$col("Species") == "setosa")$collect() diff --git a/man/LazyFrame_first.Rd b/man/LazyFrame_first.Rd index 0e1af71c5..d79294b08 100644 --- a/man/LazyFrame_first.Rd +++ b/man/LazyFrame_first.Rd @@ -13,6 +13,6 @@ A LazyFrame with one row Get the first row of a LazyFrame } \examples{ -pl$LazyFrame(mtcars)$first()$collect() +as_polars_lf(mtcars)$first()$collect() } \keyword{DataFrame} diff --git a/man/LazyFrame_last.Rd b/man/LazyFrame_last.Rd index 35c6659f6..46015e4a1 100644 --- a/man/LazyFrame_last.Rd +++ b/man/LazyFrame_last.Rd @@ -13,6 +13,6 @@ A LazyFrame with one row Aggregate the columns in the LazyFrame to their maximum value. } \examples{ -pl$LazyFrame(mtcars)$last()$collect() +as_polars_lf(mtcars)$last()$collect() } \keyword{LazyFrame} diff --git a/man/LazyFrame_max.Rd b/man/LazyFrame_max.Rd index 79ea65101..de7e0ac17 100644 --- a/man/LazyFrame_max.Rd +++ b/man/LazyFrame_max.Rd @@ -13,6 +13,6 @@ A LazyFrame with one row Aggregate the columns in the LazyFrame to their maximum value. } \examples{ -pl$LazyFrame(mtcars)$max()$collect() +as_polars_lf(mtcars)$max()$collect() } \keyword{LazyFrame} diff --git a/man/LazyFrame_mean.Rd b/man/LazyFrame_mean.Rd index b03614aed..097bb5337 100644 --- a/man/LazyFrame_mean.Rd +++ b/man/LazyFrame_mean.Rd @@ -13,6 +13,6 @@ A LazyFrame with one row Aggregate the columns in the LazyFrame to their mean value. } \examples{ -pl$LazyFrame(mtcars)$mean()$collect() +as_polars_lf(mtcars)$mean()$collect() } \keyword{LazyFrame} diff --git a/man/LazyFrame_median.Rd b/man/LazyFrame_median.Rd index 64cde8674..e5ffb9ec4 100644 --- a/man/LazyFrame_median.Rd +++ b/man/LazyFrame_median.Rd @@ -13,6 +13,6 @@ A LazyFrame with one row Aggregate the columns in the LazyFrame to their median value. } \examples{ -pl$LazyFrame(mtcars)$median()$collect() +as_polars_lf(mtcars)$median()$collect() } \keyword{LazyFrame} diff --git a/man/LazyFrame_min.Rd b/man/LazyFrame_min.Rd index 5a242d4dd..9449c9706 100644 --- a/man/LazyFrame_min.Rd +++ b/man/LazyFrame_min.Rd @@ -13,6 +13,6 @@ A LazyFrame with one row Aggregate the columns in the LazyFrame to their minimum value. } \examples{ -pl$LazyFrame(mtcars)$min()$collect() +as_polars_lf(mtcars)$min()$collect() } \keyword{LazyFrame} diff --git a/man/LazyFrame_print.Rd b/man/LazyFrame_print.Rd index ff4c6877a..2b4a938eb 100644 --- a/man/LazyFrame_print.Rd +++ b/man/LazyFrame_print.Rd @@ -16,6 +16,6 @@ self can be used i the middle of a method chain } \examples{ -pl$LazyFrame(iris)$print() +as_polars_lf(iris)$print() } \keyword{LazyFrame} diff --git a/man/LazyFrame_profile.Rd b/man/LazyFrame_profile.Rd index c88d85c07..88943077f 100644 --- a/man/LazyFrame_profile.Rd +++ b/man/LazyFrame_profile.Rd @@ -81,7 +81,7 @@ pl$LazyFrame()$select(pl$lit(2) + 2)$profile() ## Use $profile() to compare two queries # -1- map each Species-group with native polars, takes ~120us only -pl$LazyFrame(iris)$ +as_polars_lf(iris)$ sort("Sepal.Length")$ group_by("Species", maintain_order = TRUE)$ agg(pl$col(pl$Float64)$first() + 5)$ @@ -95,7 +95,7 @@ r_func = \(s) { s$to_r()[1] + 5 } -pl$LazyFrame(iris)$ +as_polars_lf(iris)$ sort("Sepal.Length")$ group_by("Species", maintain_order = TRUE)$ agg(pl$col(pl$Float64)$map_elements(r_func))$ diff --git a/man/LazyFrame_quantile.Rd b/man/LazyFrame_quantile.Rd index aa29a50a7..4d70eeb99 100644 --- a/man/LazyFrame_quantile.Rd +++ b/man/LazyFrame_quantile.Rd @@ -20,5 +20,5 @@ Aggregate the columns in the DataFrame to a unique quantile value. Use \verb{$describe()} to specify several quantiles. } \examples{ -pl$LazyFrame(mtcars)$quantile(.4)$collect() +as_polars_lf(mtcars)$quantile(.4)$collect() } diff --git a/man/LazyFrame_reverse.Rd b/man/LazyFrame_reverse.Rd index 5b1cce949..0dc4b0e4b 100644 --- a/man/LazyFrame_reverse.Rd +++ b/man/LazyFrame_reverse.Rd @@ -13,6 +13,6 @@ LazyFrame Reverse the LazyFrame (the last row becomes the first one, etc.). } \examples{ -pl$LazyFrame(mtcars)$reverse()$collect() +as_polars_lf(mtcars)$reverse()$collect() } \keyword{LazyFrame} diff --git a/man/LazyFrame_select.Rd b/man/LazyFrame_select.Rd index 9ce5cfcba..bb668b296 100644 --- a/man/LazyFrame_select.Rd +++ b/man/LazyFrame_select.Rd @@ -19,7 +19,7 @@ Similar to \code{dplyr::mutate()}. However, it discards unmentioned columns (like \code{.()} in \code{data.table}). } \examples{ -pl$LazyFrame(iris)$select( +as_polars_lf(iris)$select( pl$col("Sepal.Length")$abs()$alias("abs_SL"), (pl$col("Sepal.Length") + 2)$alias("add_2_SL") ) diff --git a/man/LazyFrame_select_seq.Rd b/man/LazyFrame_select_seq.Rd index ff07e0a82..ae8c62bba 100644 --- a/man/LazyFrame_select_seq.Rd +++ b/man/LazyFrame_select_seq.Rd @@ -23,7 +23,7 @@ when the work per expression is cheap. Otherwise, \verb{$select()} should be preferred. } \examples{ -pl$LazyFrame(iris)$select_seq( +as_polars_lf(iris)$select_seq( pl$col("Sepal.Length")$abs()$alias("abs_SL"), (pl$col("Sepal.Length") + 2)$alias("add_2_SL") ) diff --git a/man/LazyFrame_slice.Rd b/man/LazyFrame_slice.Rd index 9eb85fdc3..de9e0b491 100644 --- a/man/LazyFrame_slice.Rd +++ b/man/LazyFrame_slice.Rd @@ -20,7 +20,7 @@ A \link[=LazyFrame_class]{LazyFrame} Get a slice of the LazyFrame. } \examples{ -pl$LazyFrame(mtcars)$slice(2, 4)$collect() -pl$LazyFrame(mtcars)$slice(30)$collect() +as_polars_lf(mtcars)$slice(2, 4)$collect() +as_polars_lf(mtcars)$slice(30)$collect() mtcars[2:6, ] } diff --git a/man/LazyFrame_std.Rd b/man/LazyFrame_std.Rd index 616e437e9..c12428639 100644 --- a/man/LazyFrame_std.Rd +++ b/man/LazyFrame_std.Rd @@ -18,6 +18,6 @@ Aggregate the columns of this LazyFrame to their standard deviation values. } \examples{ -pl$LazyFrame(mtcars)$std()$collect() +as_polars_lf(mtcars)$std()$collect() } \keyword{LazyFrame} diff --git a/man/LazyFrame_sum.Rd b/man/LazyFrame_sum.Rd index ec02c62cb..5724ba165 100644 --- a/man/LazyFrame_sum.Rd +++ b/man/LazyFrame_sum.Rd @@ -13,6 +13,6 @@ A LazyFrame with one row Aggregate the columns of this LazyFrame to their sum values. } \examples{ -pl$LazyFrame(mtcars)$sum()$collect() +as_polars_lf(mtcars)$sum()$collect() } \keyword{LazyFrame} diff --git a/man/LazyFrame_var.Rd b/man/LazyFrame_var.Rd index fa83e8d72..6c4d6b5b5 100644 --- a/man/LazyFrame_var.Rd +++ b/man/LazyFrame_var.Rd @@ -17,6 +17,6 @@ A LazyFrame with one row Aggregate the columns of this LazyFrame to their variance values. } \examples{ -pl$LazyFrame(mtcars)$var()$collect() +as_polars_lf(mtcars)$var()$collect() } \keyword{LazyFrame} diff --git a/man/LazyFrame_with_columns.Rd b/man/LazyFrame_with_columns.Rd index 4b655241e..ee1cf024b 100644 --- a/man/LazyFrame_with_columns.Rd +++ b/man/LazyFrame_with_columns.Rd @@ -19,7 +19,7 @@ the equivalent of \code{dplyr::mutate()} as it keeps unmentioned columns (unlike \verb{$select()}). } \examples{ -pl$LazyFrame(iris)$with_columns( +as_polars_lf(iris)$with_columns( pl$col("Sepal.Length")$abs()$alias("abs_SL"), (pl$col("Sepal.Length") + 2)$alias("add_2_SL") ) @@ -29,9 +29,9 @@ l_expr = list( pl$col("Sepal.Length")$abs()$alias("abs_SL"), (pl$col("Sepal.Length") + 2)$alias("add_2_SL") ) -pl$LazyFrame(iris)$with_columns(l_expr) +as_polars_lf(iris)$with_columns(l_expr) -pl$LazyFrame(iris)$with_columns( +as_polars_lf(iris)$with_columns( pl$col("Sepal.Length")$abs(), # not named expr will keep name "Sepal.Length" SW_add_2 = (pl$col("Sepal.Width") + 2) ) diff --git a/man/LazyFrame_with_columns_seq.Rd b/man/LazyFrame_with_columns_seq.Rd index c0314a3de..0432320cb 100644 --- a/man/LazyFrame_with_columns_seq.Rd +++ b/man/LazyFrame_with_columns_seq.Rd @@ -23,7 +23,7 @@ when the work per expression is cheap. Otherwise, \verb{$with_columns()} should preferred. } \examples{ -pl$LazyFrame(iris)$with_columns_seq( +as_polars_lf(iris)$with_columns_seq( pl$col("Sepal.Length")$abs()$alias("abs_SL"), (pl$col("Sepal.Length") + 2)$alias("add_2_SL") ) @@ -33,9 +33,9 @@ l_expr = list( pl$col("Sepal.Length")$abs()$alias("abs_SL"), (pl$col("Sepal.Length") + 2)$alias("add_2_SL") ) -pl$LazyFrame(iris)$with_columns_seq(l_expr) +as_polars_lf(iris)$with_columns_seq(l_expr) -pl$LazyFrame(iris)$with_columns_seq( +as_polars_lf(iris)$with_columns_seq( pl$col("Sepal.Length")$abs(), # not named expr will keep name "Sepal.Length" SW_add_2 = (pl$col("Sepal.Width") + 2) ) diff --git a/man/LazyFrame_with_row_index.Rd b/man/LazyFrame_with_row_index.Rd index b6c6c2ce0..6fab401ab 100644 --- a/man/LazyFrame_with_row_index.Rd +++ b/man/LazyFrame_with_row_index.Rd @@ -18,7 +18,7 @@ A new LazyFrame with a counter column in front Add a new column at index 0 that counts the rows } \examples{ -df = pl$LazyFrame(mtcars) +df = as_polars_lf(mtcars) # by default, the index starts at 0 (to mimic the behavior of Python Polars) df$with_row_index("idx") diff --git a/man/LazyGroupBy_ungroup.Rd b/man/LazyGroupBy_ungroup.Rd index 33474f931..428e14640 100644 --- a/man/LazyGroupBy_ungroup.Rd +++ b/man/LazyGroupBy_ungroup.Rd @@ -13,7 +13,7 @@ A new \code{LazyFrame} object. Revert the group by operation. } \examples{ -lf = pl$LazyFrame(mtcars) +lf = as_polars_lf(mtcars) lf lgb = lf$group_by("cyl") diff --git a/man/RThreadHandle_class.Rd b/man/RThreadHandle_class.Rd index 526a44d03..71b0a3435 100644 --- a/man/RThreadHandle_class.Rd +++ b/man/RThreadHandle_class.Rd @@ -30,7 +30,7 @@ prexpr = pl$col("mpg")$map_batches(\(x) { Sys.sleep(.1) x * 0.43 }, in_background = TRUE)$alias("kml") -handle = pl$LazyFrame(mtcars)$with_columns(prexpr)$collect_in_background() +handle = as_polars_lf(mtcars)$with_columns(prexpr)$collect_in_background() if (!handle$is_finished()) print("not done yet") df = handle$join() # get result df diff --git a/man/S3_extract.Rd b/man/S3_extract.Rd index 741132c92..31f3c7e01 100644 --- a/man/S3_extract.Rd +++ b/man/S3_extract.Rd @@ -30,7 +30,7 @@ Mimics the behavior of [\code{x[i, j, drop = TRUE]}][Extract] for \link{data.fra \verb{[i]} is equivalent to \verb{pl$select()[i, , drop = TRUE]}. } \examples{ -df = pl$DataFrame(data.frame(a = 1:3, b = letters[1:3])) +df = as_polars_df(data.frame(a = 1:3, b = letters[1:3])) lf = df$lazy() # Select a row diff --git a/man/S3_na.omit.Rd b/man/S3_na.omit.Rd index 13ad768ed..c9cbc8328 100644 --- a/man/S3_na.omit.Rd +++ b/man/S3_na.omit.Rd @@ -20,7 +20,7 @@ Drop missing values } \examples{ -df = pl$DataFrame(data.frame(a = c(NA, 2:10), b = c(1, NA, 3:10)))$lazy() +df = as_polars_df(data.frame(a = c(NA, 2:10), b = c(1, NA, 3:10)))$lazy() na.omit(df) na.omit(df, subset = "a") na.omit(df, subset = c("a", "b")) diff --git a/man/SQLContext_register_many.Rd b/man/SQLContext_register_many.Rd index 98e1e6272..411aa9b63 100644 --- a/man/SQLContext_register_many.Rd +++ b/man/SQLContext_register_many.Rd @@ -22,8 +22,8 @@ If a table with the same name is already registered, it will be overwritten. \dontshow{if (polars_info()$features$sql) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} ctx = pl$SQLContext() r_df = mtcars -pl_df = pl$DataFrame(mtcars) -pl_lf = pl$LazyFrame(mtcars) +pl_df = as_polars_df(mtcars) +pl_lf = as_polars_lf(mtcars) ctx$register_many(r_df = r_df, pl_df = pl_df, pl_lf = pl_lf) diff --git a/man/pl_DataFrame.Rd b/man/pl_DataFrame.Rd index a644e38b3..6120a1d38 100644 --- a/man/pl_DataFrame.Rd +++ b/man/pl_DataFrame.Rd @@ -9,10 +9,8 @@ pl_DataFrame(..., make_names_unique = TRUE, schema = NULL) \arguments{ \item{...}{One of the following: \itemize{ -\item a list of mixed vectors and Series of equal length \item mixed vectors and/or Series of equal length -\item a positional argument of a \link{data.frame} or a \link[=DataFrame_class]{DataFrame} -(not recommended use). In this case, the object will be passed to \code{\link[=as_polars_df]{as_polars_df()}}. +\item a list of mixed vectors and Series of equal length (Deprecated, please use \code{\link[=as_polars_df]{as_polars_df()}} instead). } Columns will be named as of named arguments or alternatively by names of @@ -22,7 +20,7 @@ Series or given a placeholder name.} prefixed a running number.} \item{schema}{A named list that will be used to convert a variable to a -specific DataType. See Examples.} +specific DataType. Same as \code{schema_overrides} of \code{\link[=as_polars_df]{as_polars_df()}}.} } \value{ \link[=DataFrame_class]{DataFrame} @@ -37,20 +35,6 @@ pl$DataFrame( c = letters[1:5], d = list(1:1, 1:2, 1:3, 1:4, 1:5) ) # directly from vectors - -# from a list of vectors -pl$DataFrame(list( - a = c(1, 2, 3, 4, 5), - b = 1:5, - c = letters[1:5], - d = list(1L, 1:2, 1:3, 1:4, 1:5) -)) - -# from a data.frame -pl$DataFrame(mtcars) - -# custom schema -pl$DataFrame(iris, schema = list(Sepal.Length = pl$Float32, Species = pl$String)) } \seealso{ \itemize{ diff --git a/man/pl_corr.Rd b/man/pl_corr.Rd index c359208ea..378db1527 100644 --- a/man/pl_corr.Rd +++ b/man/pl_corr.Rd @@ -26,6 +26,6 @@ Expr for the computed correlation Calculates the correlation between two columns } \examples{ -lf = pl$LazyFrame(data.frame(a = c(1, 8, 3), b = c(4, 5, 2))) +lf = as_polars_lf(data.frame(a = c(1, 8, 3), b = c(4, 5, 2))) lf$select(pl$corr("a", "b", method = "spearman"))$collect() } diff --git a/man/pl_cov.Rd b/man/pl_cov.Rd index 1c191dd77..5f3b12981 100644 --- a/man/pl_cov.Rd +++ b/man/pl_cov.Rd @@ -20,7 +20,7 @@ Expr for the computed covariance Calculates the covariance between two columns / expressions. } \examples{ -lf = pl$LazyFrame(data.frame(a = c(1, 8, 3), b = c(4, 5, 2))) +lf = as_polars_lf(data.frame(a = c(1, 8, 3), b = c(4, 5, 2))) lf$select(pl$cov("a", "b"))$collect() pl$cov(c(1, 8, 3), c(4, 5, 2))$to_r() } diff --git a/man/pl_fold.Rd b/man/pl_fold.Rd index 1425e517d..ad924361e 100644 --- a/man/pl_fold.Rd +++ b/man/pl_fold.Rd @@ -22,7 +22,7 @@ This allows one to do rowwise operations, starting with an initial value value. } \examples{ -df = pl$DataFrame(mtcars) +df = as_polars_df(mtcars) # Make the row-wise sum of all columns df$with_columns( diff --git a/man/pl_implode.Rd b/man/pl_implode.Rd index fcc196d08..f5d9b50a1 100644 --- a/man/pl_implode.Rd +++ b/man/pl_implode.Rd @@ -17,5 +17,5 @@ See \code{\link[=pl_col]{?pl_col}} for details.} This function is syntactic sugar for \code{pl$col(...)$implode()}. } \examples{ -pl$DataFrame(iris)$select(pl$implode("Species")) +as_polars_df(iris)$select(pl$implode("Species")) } diff --git a/man/pl_is_schema.Rd b/man/pl_is_schema.Rd index 252056700..0355e0a6f 100644 --- a/man/pl_is_schema.Rd +++ b/man/pl_is_schema.Rd @@ -16,7 +16,7 @@ bool check if schema } \examples{ -pl$is_schema(pl$DataFrame(iris)$schema) +pl$is_schema(as_polars_df(iris)$schema) pl$is_schema(list("alice", "bob")) } \keyword{functions} diff --git a/man/pl_reduce.Rd b/man/pl_reduce.Rd index 3fb7fcc50..e94162dfc 100644 --- a/man/pl_reduce.Rd +++ b/man/pl_reduce.Rd @@ -19,7 +19,7 @@ This allows one to do rowwise operations. See \code{\link[=pl_fold]{pl$fold()}} operations with an initial value. } \examples{ -df = pl$DataFrame(mtcars) +df = as_polars_df(mtcars) # Make the row-wise sum of all columns df$with_columns( diff --git a/man/pl_rolling_corr.Rd b/man/pl_rolling_corr.Rd index 5196d16c0..bab9e0a87 100644 --- a/man/pl_rolling_corr.Rd +++ b/man/pl_rolling_corr.Rd @@ -25,6 +25,6 @@ Expr for the computed rolling correlation Calculates the rolling correlation between two columns } \examples{ -lf = pl$LazyFrame(data.frame(a = c(1, 8, 3), b = c(4, 5, 2))) +lf = as_polars_lf(data.frame(a = c(1, 8, 3), b = c(4, 5, 2))) lf$select(pl$rolling_corr("a", "b", window_size = 2))$collect() } diff --git a/man/pl_rolling_cov.Rd b/man/pl_rolling_cov.Rd index 8e7bd999a..282920b59 100644 --- a/man/pl_rolling_cov.Rd +++ b/man/pl_rolling_cov.Rd @@ -25,6 +25,6 @@ Expr for the computed rolling covariance Calculates the rolling covariance between two columns } \examples{ -lf = pl$LazyFrame(data.frame(a = c(1, 8, 3), b = c(4, 5, 2))) +lf = as_polars_lf(data.frame(a = c(1, 8, 3), b = c(4, 5, 2))) lf$select(pl$rolling_cov("a", "b", window_size = 2))$collect() } diff --git a/man/pl_with_string_cache.Rd b/man/pl_with_string_cache.Rd index 5e3414a9d..7e33226db 100644 --- a/man/pl_with_string_cache.Rd +++ b/man/pl_with_string_cache.Rd @@ -18,8 +18,8 @@ This function only temporarily enables the global string cache. \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)) } diff --git a/man/polars_class_object.Rd b/man/polars_class_object.Rd index cb2cd2937..fd4a10492 100644 --- a/man/polars_class_object.Rd +++ b/man/polars_class_object.Rd @@ -19,13 +19,13 @@ See function macro_add_syntax_check_to_class(). } \examples{ # all a polars object is only made of: -some_polars_object = pl$DataFrame(iris) +some_polars_object = as_polars_df(iris) str(some_polars_object) # External Pointer tagged with a class attribute. # All state is stored on rust side. # The single exception from the rule is class "GroupBy", where objects also have # two private attributes "groupby_input" and "maintain_order". -str(pl$DataFrame(iris)$group_by("Species")) +str(as_polars_df(iris)$group_by("Species")) } \keyword{api_object} diff --git a/tests/testthat/_snaps/dataframe.md b/tests/testthat/_snaps/dataframe.md index 2b207626e..27160f187 100644 --- a/tests/testthat/_snaps/dataframe.md +++ b/tests/testthat/_snaps/dataframe.md @@ -412,7 +412,7 @@ --- Code - pl$DataFrame(mtcars)$describe() + as_polars_df(mtcars)$describe() Output shape: (9, 12) ┌────────────┬───────────┬──────────┬────────────┬───┬──────────┬──────────┬──────────┬────────┐ @@ -434,7 +434,7 @@ --- Code - pl$DataFrame(mtcars)$describe(interpolation = "linear") + as_polars_df(mtcars)$describe(interpolation = "linear") Output shape: (9, 12) ┌────────────┬───────────┬──────────┬────────────┬───┬──────────┬──────────┬──────────┬────────┐ diff --git a/tests/testthat/_snaps/deparse/dataframe.md b/tests/testthat/_snaps/deparse/dataframe.md index 009d30f5b..84ec3ad1b 100644 --- a/tests/testthat/_snaps/deparse/dataframe.md +++ b/tests/testthat/_snaps/deparse/dataframe.md @@ -1,53 +1,53 @@ # describe Code - pl$DataFrame(mtcars)$describe()$to_list() + as_polars_df(mtcars)$describe()$to_list() Output $describe - [1] "count" "null_count" "mean" "std" "min" - [6] "max" "median" "25pct" "75pct" - + [1] "count" "null_count" "mean" "std" "min" + [6] "max" "median" "25pct" "75pct" + $mpg [1] 32.000000 0.000000 20.090625 6.026948 10.400000 33.900000 19.200000 [8] 15.500000 22.800000 - + $cyl [1] 32.000000 0.000000 6.187500 1.785922 4.000000 8.000000 6.000000 [8] 4.000000 8.000000 - + $disp [1] 32.0000 0.0000 230.7219 123.9387 71.1000 472.0000 196.3000 121.0000 [9] 350.0000 - + $hp [1] 32.00000 0.00000 146.68750 68.56287 52.00000 335.00000 123.00000 [8] 97.00000 180.00000 - + $drat [1] 32.0000000 0.0000000 3.5965625 0.5346787 2.7600000 4.9300000 3.6950000 [8] 3.0800000 3.9200000 - + $wt [1] 32.0000000 0.0000000 3.2172500 0.9784574 1.5130000 5.4240000 3.3250000 [8] 2.6200000 3.7300000 - + $qsec [1] 32.000000 0.000000 17.848750 1.786943 14.500000 22.900000 17.710000 [8] 16.900000 18.900000 - + $vs [1] 32.0000000 0.0000000 0.4375000 0.5040161 0.0000000 1.0000000 0.0000000 [8] 0.0000000 1.0000000 - + $am [1] 32.0000000 0.0000000 0.4062500 0.4989909 0.0000000 1.0000000 0.0000000 [8] 0.0000000 1.0000000 - + $gear [1] 32.0000000 0.0000000 3.6875000 0.7378041 3.0000000 5.0000000 4.0000000 [8] 3.0000000 4.0000000 - + $carb [1] 32.0000 0.0000 2.8125 1.6152 1.0000 8.0000 2.0000 2.0000 4.0000 - + diff --git a/tests/testthat/_snaps/pkg-knitr.md b/tests/testthat/_snaps/pkg-knitr.md index 9abd548df..9fbea81cd 100644 --- a/tests/testthat/_snaps/pkg-knitr.md +++ b/tests/testthat/_snaps/pkg-knitr.md @@ -13,7 +13,7 @@ ``` r df = data.frame(a = 1:3, b = letters[1:3]) - pl$DataFrame(df) + as_polars_df(df) ``` ```{=html} @@ -42,7 +42,7 @@ ``` r df = data.frame(a = 1:3, b = letters[1:3]) - pl$DataFrame(df) + as_polars_df(df) ``` ```{=html} @@ -64,7 +64,7 @@ ``` r df = data.frame(a = 1:3, b = letters[1:3]) - pl$DataFrame(df) + as_polars_df(df) ```