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

gshift gives wrong results in subsetting queries #5962

Closed
MichaelChirico opened this issue Feb 25, 2024 · 3 comments · Fixed by #5963
Closed

gshift gives wrong results in subsetting queries #5962

MichaelChirico opened this issue Feb 25, 2024 · 3 comments · Fixed by #5963
Labels
GForce issues relating to optimized grouping calculations (GForce) regression
Milestone

Comments

@MichaelChirico
Copy link
Member

          I encounter this problem too with the following example:
library(data.table)

dt <- expand.grid(
  date = 1:10,
  time = 1:10,
  id = 1:5
)

setDT(dt, key = c("date", "time", "id"))
dt[, x := runif(.N)]
dt[time == 1, x1 := shift(x, type = "lead"), by = id]

previous producing

Key: <date, time, id>
Index: <time>
      date  time    id         x        x1
     <int> <int> <int>     <num>     <num>
  1:     1     1     1 0.1217285 0.2041882
  2:     1     1     2 0.2499479 0.3632787
  3:     1     1     3 0.9992822 0.3553096
  4:     1     1     4 0.9851168 0.1797294
  5:     1     1     5 0.2273191 0.2967562
 ---                                      
496:    10    10     1 0.2503363        NA
497:    10    10     2 0.2226453        NA
498:    10    10     3 0.3320792        NA
499:    10    10     4 0.3255982        NA
500:    10    10     5 0.1976716        NA

but now producing

> dt
Key: <date, time, id>
Index: <time>
      date  time    id          x                                                                    x1
     <int> <int> <int>      <num>                                                                <list>
  1:     1     1     1 0.74905819 0.59769795,0.30605044,0.74046541,0.08694826,0.24060779,0.89059279,...
  2:     1     1     2 0.51506472 0.59769795,0.30605044,0.74046541,0.08694826,0.24060779,0.89059279,...
  3:     1     1     3 0.82395315 0.59769795,0.30605044,0.74046541,0.08694826,0.24060779,0.89059279,...
  4:     1     1     4 0.81986857 0.59769795,0.30605044,0.74046541,0.08694826,0.24060779,0.89059279,...
  5:     1     1     5 0.78196531 0.59769795,0.30605044,0.74046541,0.08694826,0.24060779,0.89059279,...
 ---                                                                                                   
496:    10    10     1 0.53337552                                                                      
497:    10    10     2 0.03719923                                                                      
498:    10    10     3 0.73477434                                                                      
499:    10    10     4 0.03107033                                                                      
500:    10    10     5 0.72256881                               

Originally posted by @renkun-ken in #5939 (comment)

@MichaelChirico MichaelChirico added regression GForce issues relating to optimized grouping calculations (GForce) labels Feb 25, 2024
@MichaelChirico MichaelChirico added this to the 1.15.2 milestone Feb 25, 2024
@TysonStanley TysonStanley modified the milestones: 1.15.2, 1.15.4 Feb 27, 2024
@aattp
Copy link

aattp commented Mar 12, 2024

You may want to have a look to this example as well, I guess it is related: https://stackoverflow.com/q/78121802/20928710

@MichaelChirico
Copy link
Member Author

Thanks @aattp, can you confirm the issue is fixed for you on current master?

@aattp
Copy link

aattp commented Mar 12, 2024

Yes, it works using the current master!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GForce issues relating to optimized grouping calculations (GForce) regression
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants