Skip to content

LOCF doesn't work with negative integer64 keys #1405

@bryan4887

Description

@bryan4887

I'm not sure if this is me misusing integer64 or data.table, but this is very unexpected behavior:

LOCF with positive integer64 keys:

library(data.table)
library(bit64)
x <- data.table(times=as.integer64(1000 + c(-1000, 0, 100, 1000)), vals=c(0, 10, 0, 1), key="times")
x[J(as.integer64(1000 + seq(-1000, 1000, by=100))), roll=TRUE]
    times vals
 1:     0    0
 2:   100    0
 3:   200    0
 4:   300    0
 5:   400    0
 6:   500    0
 7:   600    0
 8:   700    0
 9:   800    0
10:   900    0
11:  1000   10
12:  1100    0
13:  1200    0
14:  1300    0
15:  1400    0
16:  1500    0
17:  1600    0
18:  1700    0
19:  1800    0
20:  1900    0
21:  2000    1
    times vals

Good, that's what we'd expect.

LOCF with negative integer64 keys:
But when the keys go negative, LOCF stops working when using integer64 as keys.

x <- data.table(times=as.integer64(c(-1000, 0, 100, 1000)), vals=c(0, 10, 0, 1), key="times")
x[J(as.integer64(seq(-1000, 1000, by=100))), roll=TRUE]

    times vals
 1: -1000    0
 2:  -900   NA
 3:  -800   NA
 4:  -700   NA
 5:  -600   NA
 6:  -500   NA
 7:  -400   NA
 8:  -300   NA
 9:  -200   NA
10:  -100   NA
11:     0   10
12:   100    0
13:   200    0
14:   300    0
15:   400    0
16:   500    0
17:   600    0
18:   700    0
19:   800    0
20:   900    0
21:  1000    1
    times vals

LOCF with negative integer keys:
Not with regular integers:

x <- data.table(times= c(-1000, 0, 100, 1000), vals=c(0, 10, 0, 1), key="times")
x[J(seq(-1000, 1000, by=100)), roll=TRUE]
    times vals
 1: -1000    0
 2:  -900    0
 3:  -800    0
 4:  -700    0
 5:  -600    0
 6:  -500    0
 7:  -400    0
 8:  -300    0
 9:  -200    0
10:  -100    0
11:     0   10
12:   100    0
13:   200    0
14:   300    0
15:   400    0
16:   500    0
17:   600    0
18:   700    0
19:   800    0
20:   900    0
21:  1000    1
    times vals

I thought it might be related to this issue ( #1404 ) but changing the numerical rounding had no effect.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions