nealrichardson commented on code in PR #12751:
URL: https://github.com/apache/arrow/pull/12751#discussion_r852182930
##########
r/tests/testthat/test-RecordBatch.R:
##########
@@ -513,6 +513,76 @@ test_that("record_batch() with different length arrays", {
expect_error(record_batch(a = 1:5, b = 1:6), msg)
})
+test_that("RecordBatch doesn't support rbind", {
+ expect_snapshot_error(
+ rbind(
+ record_batch(a = 1:10),
+ record_batch(a = 2:4)
+ )
+ )
+})
+
+test_that("RecordBatch supports cbind", {
+ expect_snapshot_error(
+ cbind(
+ record_batch(a = 1:10),
+ record_batch(a = c("a", "b"))
+ )
+ )
+
+ actual <- cbind(
+ record_batch(a = c(1, 2), b = c("a", "b")),
+ record_batch(a = c("d", "c")),
+ record_batch(c = c(2, 3))
+ )
+ expected <- record_batch(
+ a = c(1, 2),
+ b = c("a", "b"),
+ a = c("d", "c"),
+ c = c(2, 3)
+ )
+ expect_equal(actual, expected)
+
+ # Handles arrays
+ expect_equal(
+ cbind(record_batch(a = 1:2), b = Array$create(4:5)),
+ record_batch(a = 1:2, b = 4:5)
+ )
+
+ # Handles data.frames on R 4.0 or greater
+ if (getRversion() >= "4.0.0") {
+ # Prior to R 4.0, cbind would short-circuit to the data.frame
implementation
+ # if **any** of the arguments are a data.frame.
+ expect_equal(
+ cbind(record_batch(a = 1:2), data.frame(b = 4:5)),
+ record_batch(a = 1:2, b = 4:5)
+ )
+ }
+
+
+ # Handles base factors
+ expect_equal(
+ cbind(record_batch(a = 1:2), b = factor(c("a", "b"))),
+ record_batch(a = 1:2, b = factor(c("a", "b")))
+ )
+
+ # Handles base scalars
+ expect_equal(
+ cbind(record_batch(a = 1:2), b = 1L),
+ record_batch(a = 1:2, b = rep(1L, 2))
+ )
+
+ # Handles unnamed arrays, even in cases where no named arguments are passed
Review Comment:
IMO we should be consistent, and this is one of those behaviors were R is a
little too loose, so I'd drop it and be more strict.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]