Skip to content

Commit

Permalink
refactor: fix some lints (#1176)
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennebacher authored Aug 8, 2024
1 parent 550c800 commit 3d7c2ff
Show file tree
Hide file tree
Showing 16 changed files with 92 additions and 113 deletions.
2 changes: 1 addition & 1 deletion R/dataframe__frame.R
Original file line number Diff line number Diff line change
Expand Up @@ -1638,7 +1638,7 @@ DataFrame_rename = function(...) {
#' df
#'
#' df$describe()
DataFrame_describe = function(percentiles = c(.25, .75), interpolation = "nearest") {
DataFrame_describe = function(percentiles = c(0.25, 0.75), interpolation = "nearest") {
uw = \(res) unwrap(res, "in $describe():")

if (length(self$columns) == 0) {
Expand Down
2 changes: 1 addition & 1 deletion R/polars_envvars.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ polars_envvars = function() {
c("POLARS_WARN_UNSTABLE", "0")
) |> as.data.frame()
out = vector("list", length(envvars))
for (i in 1:nrow(envvars)) {
for (i in seq_len(nrow(envvars))) {
e = envvars[[1]][i]
out[[e]] = Sys.getenv(e, unset = envvars[[2]][i])
}
Expand Down
6 changes: 3 additions & 3 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ get_method_usages = function(env, pattern = "") {
paste0_len = function(..., collapse = NULL, sep = "") {
dot_args = list2(...)
# any has zero length, return zero length
if (any(!sapply(dot_args, length))) {
if (!all(lengths(dot_args))) {
character()
} else {
paste(..., collapse = collapse, sep = sep)
Expand Down Expand Up @@ -385,7 +385,7 @@ print_env = function(api, name, max_depth = 10) {
#' @noRd
#' @return X without any AsIs subclass
unAsIs = function(X) {
if ("AsIs" %in% class(X)) {
if (inherits(X, "AsIs")) {
class(X) = class(X)[-match("AsIs", class(X))]
}
X
Expand Down Expand Up @@ -421,7 +421,7 @@ restruct_list = function(l) {
if (!length(structs_found_list)) {
return(l)
}
structs_found_list = structs_found_list |> (\(x) x[order(-sapply(x, length))])()
structs_found_list = structs_found_list |> (\(x) x[order(-lengths(x))])()

val = NULL # to satisyfy R CMD check no undefined global
# restruct all tags in list
Expand Down
4 changes: 2 additions & 2 deletions inst/misc/develop_polars.R
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ find_missing_return = function() {
has_value()
})

names(all_doc_values[sapply(all_doc_values, length) < 1])
names(all_doc_values[lengths(all_doc_values) < 1])
}


Expand Down Expand Up @@ -298,7 +298,7 @@ run_all_examples_collect_errors = \(skip_these = character(), time_examples = FA
if (time_examples) {
t2 = Sys.time()
duration = difftime(t2, t1, units = "secs")
if (duration > .1) cat(" ", duration, "s")
if (duration > 0.1) cat(" ", duration, "s")
}
if (!is.null(err)) list(err = err, txt = txt)
})
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ make_print_cases = function() {
expect_rpolarserr = function(expr, ctxs) {
res = result(expr)
expect_identical(class(res$err), "RPolarsErr")
expect_identical(names(res$err$contexts()), ctxs)
expect_named(res$err$contexts(), ctxs)
}

expect_snapshot_file = function(path, ...) {
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test-Rerr.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ test_that("can add any context to err", {
rpolarserr = .pr$Err$new()
for (i in err_types) rpolarserr = rpolarserr[[i]](i)

expect_identical(
names(rpolarserr$contexts()),
expect_named(
rpolarserr$contexts(),
c(
"When", "PlainErrorMessage", "ValueOutOfScope", "TypeMismatch",
"Hint", "BadValue", "BadValue", "BadArgument"
Expand All @@ -20,11 +20,11 @@ test_that("set/replace/read rcall & rinfo", {
err1 = err0$rinfo("in $foo()")
err2 = err1$rinfo("in $bar()")

expect_identical(err0$get_rinfo(), NULL)
expect_null(err0$get_rinfo())
expect_identical(err1$get_rinfo(), "in $foo()")
expect_identical(err2$get_rinfo(), "in $bar()")

expect_identical(err2$get_rcall(), NULL)
expect_null(err2$get_rcall())
err_a = unwrap_err(result(unwrap(Err(err2), "in $bob()")))
expect_identical(err_a$get_rcall(), call_to_string(sys.call(1)))

Expand All @@ -39,6 +39,6 @@ test_that("err_on_named_args", {

# err on named args
ctx = err_on_named_args(a = 1, b = 2)$err$contexts()
expect_identical(names(ctx), c("Hint", "PlainErrorMessage", "BadArgument"))
expect_named(ctx, c("Hint", "PlainErrorMessage", "BadArgument"))
expect_identical(ctx$BadArgument, "a, b")
})
6 changes: 3 additions & 3 deletions tests/testthat/test-as_polars.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ patrick::with_parameters_test_that(
pl_series = as_polars_series(x)
expect_s3_class(pl_series, "RPolarsSeries")

expect_identical(length(pl_series), 1L)
expect_length(pl_series, 1L)
expect_equal(pl_series$name, expected_name)

if (inherits(x, "nanoarrow_array_stream")) {
Expand Down Expand Up @@ -204,7 +204,7 @@ test_that("tests for vctrs_rcrd", {

vec = latlon(c(32.71, 2.95), c(-117.17, 1.67))

expect_identical(length(as_polars_series(vec)), 2L)
expect_length(as_polars_series(vec), 2L)

expect_snapshot(pl$DataFrame(foo = vec)$dtypes, cran = TRUE)

Expand Down Expand Up @@ -353,7 +353,7 @@ patrick::with_parameters_test_that("as_polars_series for nanoarrow_array_stream"
expect_s3_class(pl_series, "RPolarsSeries")
expect_grepl_error(x$get_next(), "already been released")

expect_identical(length(pl_series), 2L)
expect_length(pl_series, 2L)
},
.cases = make_nanoarrow_array_stream_cases()
)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-csv-read.R
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,6 @@ test_that("cache url tempfile", {
check_is_link(url, reuse_downloaded = TRUE)
attempt_2 = cache_temp_file[[url]]

expect_true(!is.null(cache_temp_file[[url]]))
expect_false(is.null(cache_temp_file[[url]]))
expect_equal(attempt_1, attempt_2)
})
13 changes: 5 additions & 8 deletions tests/testthat/test-dataframe.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,7 @@ test_that("get set properties", {
))
)

expect_equal(
df$columns,
names(df$schema)
)
expect_named(df$schema, df$columns)
})


Expand All @@ -152,7 +149,7 @@ test_that("DataFrame, custom schema", {
FUN = "=="
))
)
expect_identical(names(df$schema), names(iris))
expect_named(df$schema, names(iris))

# works fine if a variable is called "schema"
expect_no_error(
Expand Down Expand Up @@ -458,7 +455,7 @@ test_that("with_columns: create a list variable", {
test_that("with_columns lazy/eager", {
l = list(
a = 1:4,
b = c(.5, 4, 10, 13),
b = c(0.5, 4, 10, 13),
c = c(TRUE, TRUE, FALSE, TRUE)
)
df = pl$DataFrame(l)
Expand Down Expand Up @@ -523,7 +520,7 @@ test_that("with_columns_seq", {
test_that("head lazy/eager", {
l = list(
a = 1:4,
b = c(.5, 4, 10, 13),
b = c(0.5, 4, 10, 13),
c = c(TRUE, TRUE, FALSE, TRUE)
)
df = pl$DataFrame(l)
Expand Down Expand Up @@ -630,7 +627,7 @@ test_that("simple translations", {
expect_equal(a, b, ignore_attr = TRUE)

a = pl$DataFrame(mtcars)$estimated_size()
expect_equal(a, 2816, tolerance = .1)
expect_equal(a, 2816, tolerance = 0.1)

# trigger u8 conversion errors
expect_grepl_error(pl$DataFrame(mtcars)$std(256), c("ddof", "exceed the upper bound for u8 of 255"))
Expand Down
Loading

0 comments on commit 3d7c2ff

Please sign in to comment.