You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2019/02/27 04:12:38 UTC
[arrow] branch master updated: ARROW-3816: [R] nrow.RecordBatch
method
This is an automated email from the ASF dual-hosted git repository.
wesm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new 41fc38f ARROW-3816: [R] nrow.RecordBatch method
41fc38f is described below
commit 41fc38f05afdf1cc4955216d744b2e17901d7882
Author: Romain Francois <ro...@purrple.cat>
AuthorDate: Tue Feb 26 22:12:29 2019 -0600
ARROW-3816: [R] nrow.RecordBatch method
``` r
library(arrow)
tab <- table(tibble::tibble(x = 1:10, y = 1:10))
dim(tab)
#> [1] 10 2
nrow(tab)
#> [1] 10
ncol(tab)
#> [1] 2
```
This just implements `dim()`.
`nrow()` and `ncol()` are derived from it:
```r
> nrow
function (x)
dim(x)[1L]
<bytecode: 0x1045a65b8>
<environment: namespace:base>
> ncol
function (x)
dim(x)[2L]
<bytecode: 0x10e2f4dd0>
<environment: namespace:base>
```
Author: Romain Francois <ro...@purrple.cat>
Closes #3563 from romainfrancois/ARROW-3816/nrow_RecordBatch and squashes the following commits:
f34efc24 <Romain Francois> export dim.Table
7977678a <Romain Francois> minor name fix
4ebd254a <Romain Francois> dim.(RecordBatch,Table)
---
r/NAMESPACE | 2 ++
r/R/RecordBatch.R | 5 +++++
r/R/Table.R | 5 +++++
r/tests/testthat/test-RecordBatch.R | 8 +++++++-
r/tests/testthat/test-Table.R | 6 ++++++
5 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/r/NAMESPACE b/r/NAMESPACE
index 4636c12..9706648 100644
--- a/r/NAMESPACE
+++ b/r/NAMESPACE
@@ -51,6 +51,8 @@ S3method(csv_table_reader,"arrow::io::InputStream")
S3method(csv_table_reader,character)
S3method(csv_table_reader,default)
S3method(csv_table_reader,fs_path)
+S3method(dim,"arrow::RecordBatch")
+S3method(dim,"arrow::Table")
S3method(length,"arrow::Array")
S3method(names,"arrow::RecordBatch")
S3method(print,"arrow-enum")
diff --git a/r/R/RecordBatch.R b/r/R/RecordBatch.R
index 9872117..22fda84 100644
--- a/r/R/RecordBatch.R
+++ b/r/R/RecordBatch.R
@@ -80,6 +80,11 @@
}
#' @export
+`dim.arrow::RecordBatch` <- function(x) {
+ c(x$num_rows, x$num_columns)
+}
+
+#' @export
`as_tibble.arrow::RecordBatch` <- function(x, use_threads = TRUE, ...){
RecordBatch__to_dataframe(x, use_threads = use_threads)
}
diff --git a/r/R/Table.R b/r/R/Table.R
index c39fce2..54731ca 100644
--- a/r/R/Table.R
+++ b/r/R/Table.R
@@ -64,3 +64,8 @@ table <- function(.data){
`as_tibble.arrow::Table` <- function(x, use_threads = TRUE, ...){
Table__to_dataframe(x, use_threads = use_threads)
}
+
+#' @export
+`dim.arrow::Table` <- function(x) {
+ c(x$num_rows, x$num_columns)
+}
diff --git a/r/tests/testthat/test-RecordBatch.R b/r/tests/testthat/test-RecordBatch.R
index 29f9094..da09984 100644
--- a/r/tests/testthat/test-RecordBatch.R
+++ b/r/tests/testthat/test-RecordBatch.R
@@ -109,7 +109,7 @@ test_that("RecordBatch with 0 rows are supported", {
})
test_that("RecordBatch cast (ARROW-3741)", {
- batch <- table(tibble::tibble(x = 1:10, y = 1:10))
+ batch <- record_batch(tibble::tibble(x = 1:10, y = 1:10))
expect_error(batch$cast(schema(x = int32())))
expect_error(batch$cast(schema(x = int32(), z = int32())))
@@ -120,3 +120,9 @@ test_that("RecordBatch cast (ARROW-3741)", {
expect_equal(batch2$column(0L)$type, int16())
expect_equal(batch2$column(1L)$type, int64())
})
+
+test_that("RecordBatch dim() and nrow() (ARROW-3816)", {
+ batch <- record_batch(tibble::tibble(x = 1:10, y = 1:10))
+ expect_equal(dim(batch), c(10L, 2L))
+ expect_equal(nrow(batch), 10L)
+})
diff --git a/r/tests/testthat/test-Table.R b/r/tests/testthat/test-Table.R
index ec1be9b..068b30f 100644
--- a/r/tests/testthat/test-Table.R
+++ b/r/tests/testthat/test-Table.R
@@ -68,3 +68,9 @@ test_that("Table cast (ARROW-3741)", {
expect_equal(tab2$column(0L)$type, int16())
expect_equal(tab2$column(1L)$type, int64())
})
+
+test_that("Table dim() and nrow() (ARROW-3816)", {
+ tab <- table(tibble::tibble(x = 1:10, y = 1:10))
+ expect_equal(dim(tab), c(10L, 2L))
+ expect_equal(nrow(tab), 10L)
+})