Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all.equal dispatches to column methods #4546

Merged
merged 12 commits into from
Jul 13, 2024
10 changes: 7 additions & 3 deletions R/setops.R
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ all.equal.data.table = function(target, current, trim.levels=TRUE, check.attribu
# trim.levels moved here
x = target[[i]]
y = current[[i]]
if (xor(is.factor(x),is.factor(y)))
if (XOR(is.factor(x), is.factor(y)))
stopf("Internal error: factor type mismatch should have been caught earlier") # nocov
cols.r = TRUE
if (is.factor(x)) {
Expand All @@ -282,8 +282,12 @@ all.equal.data.table = function(target, current, trim.levels=TRUE, check.attribu
# dealt with according to trim.levels
}
} else {
cols.r = all.equal(unclass(x), unclass(y), tolerance=tolerance, ..., check.attributes=check.attributes)
# classes were explicitly checked earlier above, so ignore classes here.
# for test 1710.5 and #4543, we want to (1) make sure we dispatch to
# any existing all.equal methods for x while also (2) treating class(x)/class(y)
# as attributes as regards check.attributes argument
cols.r = all.equal(x, y, tolerance=tolerance, ..., check.attributes=check.attributes)
if (!isTRUE(cols.r) && !check.attributes && isTRUE(all.equal(unclass(x), unclass(y), tolerance=tolerance, ..., check.attributes=check.attributes)))
cols.r = TRUE
}
if (!isTRUE(cols.r)) return(paste0("Column '", names(target)[i], "': ", paste(cols.r,collapse=" ")))
}
Expand Down
3 changes: 3 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ vapply_1i = function(x, fun, ..., use.names = TRUE) {
vapply(X = x, FUN = fun, ..., FUN.VALUE = NA_integer_, USE.NAMES = use.names)
}

# base::xor(), but with scalar operators
XOR = function(x, y) (x || y) && !(x && y)

# not is.atomic because is.atomic(matrix) is true
cols_with_dims = function(x) vapply_1i(x, function(j) length(dim(j))) > 0L

Expand Down
5 changes: 5 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -18709,3 +18709,8 @@ if (test_bit64) local({
on.exit(library(bit64))
test(2265, DT, output="abc\\s*1$")
})

# all.equal failed to dispatch to methods of columns, #4543
DT1 = data.table(t = .POSIXct(1590973200, tz='UTC'))
DT2 = data.table(t = .POSIXct(1590974413, tz='UTC'))
test(2266, all.equal(DT1, DT2), "Column 't': Mean absolute difference: 1213")
Loading