diff --git a/NEWS.md b/NEWS.md index b68964db0..e7836bfd0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # vctrs (development version) +* Fixed tests related to changes to `dim<-()` in R-devel (#1889). + # vctrs 0.6.4 * Fixed a performance issue with `vec_c()` and ALTREP vectors (in particular, diff --git a/R/type-table.R b/R/type-table.R index 79574f88c..a70035015 100644 --- a/R/type-table.R +++ b/R/type-table.R @@ -48,8 +48,6 @@ new_table <- function(x = integer(), dim = NULL, dimnames = NULL) { abort("`dim` must be an integer vector.") } - dimnames <- dimnames %||% vec_init(list(), length(dim)) - n_elements <- prod(dim) n_x <- length(x) diff --git a/tests/testthat/helper-size.R b/tests/testthat/helper-size.R index 3b58680d1..75464e7cd 100644 --- a/tests/testthat/helper-size.R +++ b/tests/testthat/helper-size.R @@ -2,8 +2,3 @@ expect_size <- function(object, n) { expect_identical(vec_size(object), vec_cast(n, int())) } - -zap_dimnames <- function(x) { - attr(x, "dimnames") <- NULL - x -} diff --git a/tests/testthat/test-type-table.R b/tests/testthat/test-type-table.R index 0e29b23a3..a79827d37 100644 --- a/tests/testthat/test-type-table.R +++ b/tests/testthat/test-type-table.R @@ -18,34 +18,42 @@ test_that("can find a common type among tables with identical dimensions", { tab1 <- new_table() tab2 <- new_table(1:2, dim = c(1L, 2L, 1L)) - expect_identical(vec_ptype2(tab1, tab1), zap_dimnames(new_table())) - expect_identical(vec_ptype2(tab2, tab2), zap_dimnames(new_table(dim = c(0L, 2L, 1L)))) + expect_identical(vec_ptype2(tab1, tab1), new_table()) + expect_identical(vec_ptype2(tab2, tab2), new_table(dim = c(0L, 2L, 1L))) }) test_that("size is not considered in the ptype", { x <- new_table(1:2, dim = 2L) y <- new_table(1:3, dim = 3L) - expect_identical(vec_ptype2(x, y), zap_dimnames(new_table())) + expect_identical(vec_ptype2(x, y), new_table()) }) test_that("vec_ptype2() can broadcast table shapes", { x <- new_table(dim = c(0L, 1L)) y <- new_table(dim = c(0L, 2L)) - expect_identical(vec_ptype2(x, y), zap_dimnames(new_table(dim = c(0L, 2L)))) + expect_identical(vec_ptype2(x, y), new_table(dim = c(0L, 2L))) x <- new_table(dim = c(0L, 1L, 3L)) y <- new_table(dim = c(0L, 2L, 1L)) - expect_identical(vec_ptype2(x, y), zap_dimnames(new_table(dim = c(0L, 2L, 3L)))) + expect_identical(vec_ptype2(x, y), new_table(dim = c(0L, 2L, 3L))) +}) + +test_that("vec_ptype2() never propagates dimnames", { + x <- new_table(dim = c(0L, 1L), dimnames = list(character(), "x1")) + y <- new_table(dim = c(0L, 2L), dimnames = list(character(), c("y1", "y2"))) + + expect_null(dimnames(vec_ptype2(x, x))) + expect_null(dimnames(vec_ptype2(x, y))) }) test_that("implicit axes are broadcast", { x <- new_table(dim = c(0L, 2L)) y <- new_table(dim = c(0L, 1L, 3L)) - expect_identical(vec_ptype2(x, y), zap_dimnames(new_table(dim = c(0L, 2L, 3L)))) + expect_identical(vec_ptype2(x, y), new_table(dim = c(0L, 2L, 3L))) }) test_that("errors on non-broadcastable dimensions", { @@ -80,7 +88,7 @@ test_that("common types have symmetry when mixed with unspecified input", { test_that("`table` delegates coercion", { expect_identical( vec_ptype2(new_table(1), new_table(FALSE)), - zap_dimnames(new_table(double())) + new_table(double()) ) expect_error( vec_ptype2(new_table(1), new_table("")),