Skip to content

Commit

Permalink
feat: add is_polars_* functions (#658)
Browse files Browse the repository at this point in the history
  • Loading branch information
eitsupi authored Jan 3, 2024
1 parent 9f3866f commit c039011
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 0 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Collate:
'group_by.R'
'info.R'
'ipc.R'
'is_polars.R'
'json.R'
'lazyframe__group_by.R'
'lazyframe__lazy.R'
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ export(.pr)
export(as_polars_df)
export(as_polars_lf)
export(as_polars_series)
export(is_polars_df)
export(is_polars_lf)
export(is_polars_series)
export(pl)
importFrom(stats,median)
importFrom(stats,na.omit)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- New methods `$str$reverse()`, `$str$contains_any()`, and `$str$replace_many()`
(#641).
- New methods `$rle()` and `$rle_id()` (#648).
- New functions `is_polars_df()`, `is_polars_lf()`, `is_polars_series()` (#658).

### Miscellaneous

Expand Down
41 changes: 41 additions & 0 deletions R/is_polars.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#' Test if the object is a polars DataFrame
#'
#' These functions test if the object is a polars DataFrame.
#' @param x An object
#' @return A logical value
#' @export
#' @examples
#' is_polars_df(mtcars)
#'
#' is_polars_df(as_polars_df(mtcars))
is_polars_df = function(x) {
inherits(x, "RPolarsDataFrame")
}


#' Test if the object is a polars LazyFrame
#'
#' These functions test if the object is a polars LazyFrame.
#' @inherit is_polars_df params return
#' @export
#' @examples
#' is_polars_lf(mtcars)
#'
#' is_polars_lf(as_polars_lf(mtcars))
is_polars_lf = function(x) {
inherits(x, "RPolarsLazyFrame")
}


#' Test if the object is a polars Series
#'
#' These functions test if the object is a polars Series.
#' @inherit is_polars_df params return
#' @export
#' @examples
#' is_polars_series(1:3)
#'
#' is_polars_series(as_polars_series(1:3))
is_polars_series = function(x) {
inherits(x, "RPolarsSeries")
}
22 changes: 22 additions & 0 deletions man/is_polars_df.Rd

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

22 changes: 22 additions & 0 deletions man/is_polars_lf.Rd

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

22 changes: 22 additions & 0 deletions man/is_polars_series.Rd

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

17 changes: 17 additions & 0 deletions tests/testthat/test-is_polars.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
make_is_polars_cases = function() {
tibble::tribble(
~.test_name, ~is_func, ~as_func, ~x,
"is_polars_df", is_polars_df, as_polars_df, mtcars,
"is_polars_lf", is_polars_lf, as_polars_lf, mtcars,
"is_polars_series", is_polars_series, as_polars_series, 1:4,
)
}

patrick::with_parameters_test_that("is_polars_* functions",
{
polars_obj = as_func(x)
expect_true(is_func(polars_obj))
expect_false(is_func(x))
},
.cases = make_is_polars_cases()
)

0 comments on commit c039011

Please sign in to comment.