Skip to content

Commit 19f1635

Browse files
authored
Allow NULL dimnames to propagate through new_table() (#1889)
* Allow `NULL` dimnames * NEWS bullet * No need for `zap_dimnames()` anymore
1 parent a0f6aa6 commit 19f1635

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# vctrs (development version)
22

3+
* Fixed tests related to changes to `dim<-()` in R-devel (#1889).
4+
35
# vctrs 0.6.4
46

57
* Fixed a performance issue with `vec_c()` and ALTREP vectors (in particular,

R/type-table.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ new_table <- function(x = integer(), dim = NULL, dimnames = NULL) {
4848
abort("`dim` must be an integer vector.")
4949
}
5050

51-
dimnames <- dimnames %||% vec_init(list(), length(dim))
52-
5351
n_elements <- prod(dim)
5452
n_x <- length(x)
5553

tests/testthat/helper-size.R

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,3 @@
22
expect_size <- function(object, n) {
33
expect_identical(vec_size(object), vec_cast(n, int()))
44
}
5-
6-
zap_dimnames <- function(x) {
7-
attr(x, "dimnames") <- NULL
8-
x
9-
}

tests/testthat/test-type-table.R

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,42 @@ test_that("can find a common type among tables with identical dimensions", {
1818
tab1 <- new_table()
1919
tab2 <- new_table(1:2, dim = c(1L, 2L, 1L))
2020

21-
expect_identical(vec_ptype2(tab1, tab1), zap_dimnames(new_table()))
22-
expect_identical(vec_ptype2(tab2, tab2), zap_dimnames(new_table(dim = c(0L, 2L, 1L))))
21+
expect_identical(vec_ptype2(tab1, tab1), new_table())
22+
expect_identical(vec_ptype2(tab2, tab2), new_table(dim = c(0L, 2L, 1L)))
2323
})
2424

2525
test_that("size is not considered in the ptype", {
2626
x <- new_table(1:2, dim = 2L)
2727
y <- new_table(1:3, dim = 3L)
2828

29-
expect_identical(vec_ptype2(x, y), zap_dimnames(new_table()))
29+
expect_identical(vec_ptype2(x, y), new_table())
3030
})
3131

3232
test_that("vec_ptype2() can broadcast table shapes", {
3333
x <- new_table(dim = c(0L, 1L))
3434
y <- new_table(dim = c(0L, 2L))
3535

36-
expect_identical(vec_ptype2(x, y), zap_dimnames(new_table(dim = c(0L, 2L))))
36+
expect_identical(vec_ptype2(x, y), new_table(dim = c(0L, 2L)))
3737

3838
x <- new_table(dim = c(0L, 1L, 3L))
3939
y <- new_table(dim = c(0L, 2L, 1L))
4040

41-
expect_identical(vec_ptype2(x, y), zap_dimnames(new_table(dim = c(0L, 2L, 3L))))
41+
expect_identical(vec_ptype2(x, y), new_table(dim = c(0L, 2L, 3L)))
42+
})
43+
44+
test_that("vec_ptype2() never propagates dimnames", {
45+
x <- new_table(dim = c(0L, 1L), dimnames = list(character(), "x1"))
46+
y <- new_table(dim = c(0L, 2L), dimnames = list(character(), c("y1", "y2")))
47+
48+
expect_null(dimnames(vec_ptype2(x, x)))
49+
expect_null(dimnames(vec_ptype2(x, y)))
4250
})
4351

4452
test_that("implicit axes are broadcast", {
4553
x <- new_table(dim = c(0L, 2L))
4654
y <- new_table(dim = c(0L, 1L, 3L))
4755

48-
expect_identical(vec_ptype2(x, y), zap_dimnames(new_table(dim = c(0L, 2L, 3L))))
56+
expect_identical(vec_ptype2(x, y), new_table(dim = c(0L, 2L, 3L)))
4957
})
5058

5159
test_that("errors on non-broadcastable dimensions", {
@@ -80,7 +88,7 @@ test_that("common types have symmetry when mixed with unspecified input", {
8088
test_that("`table` delegates coercion", {
8189
expect_identical(
8290
vec_ptype2(new_table(1), new_table(FALSE)),
83-
zap_dimnames(new_table(double()))
91+
new_table(double())
8492
)
8593
expect_error(
8694
vec_ptype2(new_table(1), new_table("")),

0 commit comments

Comments
 (0)