Skip to content

Commit

Permalink
fix: dim() should return integer (#577)
Browse files Browse the repository at this point in the history
  • Loading branch information
eitsupi committed Dec 7, 2023
1 parent 6445153 commit 56d8e97
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
- `as_polars_df()` for `data.frame` has a new argument `make_names_unique` (#561).
- New methods `$str$to_date()`, `$str$to_time()`, `$str$to_datetime()` as
alternatives to `$str$strptime()` (#558).
- The `dim()` function for DataFrame and LazyFrame correctly returns integer instead of
double (#577).

# polars 0.11.0

Expand Down
2 changes: 1 addition & 1 deletion R/s3_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ tail.RPolarsLazyFrame = tail.RPolarsDataFrame
#'
#' @export
#' @rdname S3_dim
dim.RPolarsDataFrame = function(x) x$shape
dim.RPolarsDataFrame = function(x) as.integer(x$shape)

#' @export
#' @rdname S3_dim
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-csv-read.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test_that("works with single URL", {
})
# put messages back in the console
sink(type = "message")
expect_identical(dim(out), c(31, 6))
expect_identical(dim(out), c(31L, 6L))
})

test_that("args separator and eol work", {
Expand All @@ -49,11 +49,11 @@ test_that("args skip_rows and skip_rows_after_header work", {
write.csv(dat, tmpf, row.names = FALSE)

out = pl$read_csv(tmpf, skip_rows = 25)
expect_identical(nrow(out), 125)
expect_identical(nrow(out), 125L)
expect_named(out, c("4.8", "3.4", "1.9", "0.2", "setosa"))

out = pl$read_csv(tmpf, skip_rows_after_header = 25)
expect_identical(nrow(out), 125)
expect_identical(nrow(out), 125L)
expect_named(out, names(iris))
})

Expand Down Expand Up @@ -88,7 +88,7 @@ test_that("arg raise_if_empty works", {
"no data: empty CSV"
)
out = pl$read_csv(tmpf, raise_if_empty = FALSE)
expect_identical(dim(out), c(0, 0))
expect_identical(dim(out), c(0L, 0L))
})

# TODO: why does this one fail?
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test-s3_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,14 @@ test_that("brackets", {
expect_equal(pl$Series(letters)[1:5]$to_vector(), letters[1:5])
expect_equal(pl$Series(letters)[-5]$to_vector(), letters[-5])
})


test_that("dim should integer", {
d = dim(as_polars_df(mtcars))
expect_identical(d, dim(mtcars))
expect_true(is.integer(d))

d = dim(as_polars_lf(mtcars))
expect_identical(d, c(NA_integer_, ncol(mtcars)))
expect_true(is.integer(d))
})
4 changes: 2 additions & 2 deletions tests/testthat/test-sql.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test_that("Intialize SQLContext with LazyFrame like objects", {
UNION ALL
SELECT * FROM pl_lf"
)$collect() |> nrow(),
3 * nrow(mtcars)
3L * nrow(mtcars)
)
})

Expand All @@ -29,7 +29,7 @@ test_that("SQLContext_register, register_many, unregister", {
expect_equal(ctx$tables(), "mtcars")
expect_identical(
ctx$execute("SELECT * FROM mtcars LIMIT 5")$collect() |> nrow(),
5
5L
)

ctx$register("mtcars2", mtcars)
Expand Down

0 comments on commit 56d8e97

Please sign in to comment.