Skip to content

fsetequal() fails for single character columns #2318

@pschil

Description

@pschil

fsetequal() on 2 data.tables only containing a single character column fails to detect that they are not equal.

The following reprex:

dt.1 <- data.table(Id=(1:10))
dt.2 <- data.table(Id=(1:10))
dt.2[1, Id:=99]

# First row in dt.1 and dt.2 now are different

# This works as expected
setequal(dt.1$Id, dt.2$Id) # FALSE
fsetequal(dt.1, dt.2)      # FALSE

# ---- Inequality not detected when Id is character 
dt.1[, Id := as.character(Id)]
dt.2[, Id := as.character(Id)]
setequal(dt.1$Id, dt.2$Id) # FALSE
fsetequal(dt.1, dt.2)      # TRUE - should be FALSE as the first row is 1 vs 99

The issue seems to be with ignore.row.order in all.equal:

# In-equality detected
data.table:::all.equal.data.table(dt.1, dt.2, check.attributes = F)
# In-equality NOT detected
data.table:::all.equal.data.table(dt.1, dt.2, check.attributes = F, ignore.row.order = T)

When adding an additional column, numeric or character, fsetequal works as expected.

dt.1[, extracol1 := 1:10]
dt.2[, extracol1 := 1:10]
# Correct
fsetequal(dt.1, dt.2)    # FALSE

dt.1[, extracol1 := as.character(extracol1)]
dt.2[, extracol1 := as.character(extracol1)]
# Also correct
fsetequal(dt.1, dt.2)    # FALSE

data.table version: 1.10.4

Session Info

R version 3.4.1 (2017-06-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     
other attached packages:
[1] data.table_1.10.4
loaded via a namespace (and not attached):
[1] compiler_3.4.1 tools_3.4.1   

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions