Wrong result of a join and other problems with columns of class "Period" (lubridate)

Open
#4,974 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
r
Domain
data

Research direction

Start by running the reproducible left-join and row-filtering examples from the issue with R, data.table, and lubridate. Compare the returned Period values and row counts with the requested row ordering, then add regression coverage for both join and filtering behavior once the affected entry point is located.

Written by the indexing model from the issue text.

Description

non-atomic column

For some reason, during a left-join, a column of class Period (lubridate) seems to be simply cycled through regardless of the actual row-ordering of the resulting joined data:

require(data.table)
require(lubridate)

X <- data.table(A=c('a','a','b','b','c','c'))
Y <- data.table(A=c('a','b','c'), B=period(month=1:3))
Y[X,,on='A']

   A              B
1: a 1m 0d 0H 0M 0S
2: a 2m 0d 0H 0M 0S
3: b 3m 0d 0H 0M 0S
4: b 1m 0d 0H 0M 0S
5: c 2m 0d 0H 0M 0S
6: c 3m 0d 0H 0M 0S

X <- data.table(A=c('c','c','b'))
Y[X,,on='A']

   A              B
1: c 1m 0d 0H 0M 0S
2: c 2m 0d 0H 0M 0S
3: b 3m 0d 0H 0M 0S

In fact, data.table seems to have trouble just filtering rows when it has columns of class Period (same Y as above):

Y[1,]

Error in dimnames(x) <- dn : 
  length of 'dimnames' [1] not equal to array extent

X <- data.table(A=c('a','b'))
Y[X,,on='A']

Error in dimnames(x) <- dn : 
  length of 'dimnames' [1] not equal to array extent
In addition: Warning message:
In cbind(A = c("a", "b"), B = c("1m 0d 0H 0M 0S", "2m 0d 0H 0M 0S",  :
  number of rows of result is not a multiple of vector length (arg 1)

Output of sessionInfo():

R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    
ssystem code page: 1250

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_4.0.3
Dominant language
R
Stars
3.9k
Forks
1.1k
Avg merge
14h 4m
Merged PRs (30d)
4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Rdatatable/data.table

All issues in Rdatatable/data.table

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.