Skip to content

Fixed typeorder coercion rules for RAWSXP and LGLSXP to match base R#4195

Closed
sritchie73 wants to merge 7 commits intomasterfrom
typeorder
Closed

Fixed typeorder coercion rules for RAWSXP and LGLSXP to match base R#4195
sritchie73 wants to merge 7 commits intomasterfrom
typeorder

Conversation

@sritchie73
Copy link
Contributor

Closes #4172

Base R coercion rules mean that raw are coerced to logical, not the other way round:

c(as.raw(0), TRUE)
# [1] FALSE  TRUE

This PR fixes the typeorder in src/init.c to match the base R coercion rules. This impacts rbindlist, which will now coerce a raw column to a logical column when binding these two together.

Raw should be coerced to logical, not the other way round, e.g. c(TRUE, as.raw(1)) == c(TRUE, TRUE) - this is because there is no NA type for raw, while logicals can be NA.
Fixes failing tests 2006.1, 2006.2, and 2129.
maxType is now initialised as -1, which is not a SEXPTYPE, and the typeorder detection is skipped if the column is NULL. Once looping over all data.tables to rbind, if maxType is still -1 we know that both/all columns are NULL, and to be filled with NA_logical_.
@codecov
Copy link

codecov bot commented Jan 22, 2020

Codecov Report

Merging #4195 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4195      +/-   ##
==========================================
+ Coverage   99.61%   99.61%   +<.01%     
==========================================
  Files          72       72              
  Lines       13871    13872       +1     
==========================================
+ Hits        13817    13818       +1     
  Misses         54       54
Impacted Files Coverage Δ
src/init.c 100% <100%> (ø) ⬆️
src/rbindlist.c 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c005296...5608dcc. Read the comment docs.

TYPEORDER(maxType) where maxType==-1 silently failed
# Check rbindlist coercion rules for raw match base R (e.g. using c()) #4172
DT1 = data.table(a=as.raw(1), b=as.raw(2), c=as.raw(3), d=as.raw(4), e=as.raw(5), f=as.raw(6), g=as.raw(7), h=as.raw(8))
DT2 = data.table(a=as.raw(1), b=TRUE, c=1L, d=1.5, e=complex(real=3, imaginary=1), f="a", g=list(3:5), h=expression(1+1))
DT3 = setDT(lapply(names(DT1), function(j) c(DT1[[j]], DT2[[j]])))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noting merge conflict for this test with #4196.

To resolve, replace this line with:

DT3 = data.table(a=c(DT1$a, DT2$a), b=c(DT1$b, DT2$b), c=c(DT1$c, DT2$c),
                 d=c(DT1$d, DT2$d), e=c(DT1$e, DT2$e), f=c(DT1$f, DT2$f),
                 g=c(DT1$g, DT2$g), h=c(DT1$h, list(DT2$h)))

(i.e. because in this current PR coercion of any type with expression leads to an expression vector, while PR #4196 expects that column to be coerced to a list)

@sritchie73 sritchie73 closed this Feb 19, 2020
@MichaelChirico MichaelChirico deleted the typeorder branch July 8, 2025 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

typeorder for LGLSXP and RAWSXP in src/init.c is in conflict with R's coercion rules

2 participants

Comments