Closed jrauser closed 8 months ago
Possibly related? https://github.com/tidyverts/fable/issues/397
I think the problem is at L228 of yearweek.R. When we call new_yearweek()
we need to pass week_start=week_start(x)
.
Here's a workaround:
library(tsibble)
#>
#> Attaching package: 'tsibble'
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, union
library(tidyverse)
x<-tibble(wk=make_yearweek(2023, 23:28, week_start=7), x=23:28)
y<-tibble(wk=make_yearweek(2023, 23:28, week_start=7), y=123:128)
j1 <- inner_join(x, y, by="wk")
j1
#> # A tibble: 6 × 3
#> wk x y
#> <week> <int> <int>
#> 1 2023 W22 23 123
#> 2 2023 W23 24 124
#> 3 2023 W24 25 125
#> 4 2023 W25 26 126
#> 5 2023 W26 27 127
#> 6 2023 W27 28 128
attr(j1$wk, "week_start")
#> [1] 1
vec_ptype2.yearweek.yearweek <- function(x, y, ...) {
if (attr(x, "week_start") != attr(y, "week_start")) {
abort("Can't combine <yearweek> with different `week_start`.")
}
yearweek(NULL, week_start=attr(x, "week_start"))
}
j2 <- inner_join(x, y, by="wk")
j2
#> # A tibble: 6 × 3
#> wk x y
#> <week> <int> <int>
#> 1 2023 W23 23 123
#> 2 2023 W24 24 124
#> 3 2023 W25 25 125
#> 4 2023 W26 26 126
#> 5 2023 W27 27 127
#> 6 2023 W28 28 128
attr(j2$wk, "week_start")
#> [1] 7
Created on 2023-09-11 with reprex v2.0.2
This same problem exists with fiscal_start
in yearquater.
thanks for reporting with a reproducible example. fixed now.
The code below makes two tibbles with a yearweek that runs from 2023 W23 to W28. But when joined, the yearweek runs from W22 to W27. If week_start is set to 1, the result is as expected.