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

vec_rbind coerces POSIXlt to POSIXct #1930

Closed
Moohan opened this issue Apr 24, 2024 · 1 comment
Closed

vec_rbind coerces POSIXlt to POSIXct #1930

Moohan opened this issue Apr 24, 2024 · 1 comment

Comments

@Moohan
Copy link

Moohan commented Apr 24, 2024

I was using purrr::list_rbind() but it seems like the behaviour/bug is coming from vctrs... When combining dataframes with a POSIXlt they are coerced to POSIXct, which is not expected.

Reprex:

library(tibble)

df_list <- list(
  df1 = tibble(
    dates_lt = as.POSIXlt(Sys.time()),
    dates_ct = as.POSIXct(Sys.time())
    ),
  df2 = tibble(
    dates_lt = as.POSIXlt(Sys.time() - 60),
    dates_ct = as.POSIXct(Sys.time() - 60)
  )
)

str(purrr::list_rbind(df_list))
#> tibble [2 × 2] (S3: tbl_df/tbl/data.frame)
#>  $ dates_lt: POSIXct[1:2], format: "2024-04-24 15:02:37" "2024-04-24 15:01:37"
#>  $ dates_ct: POSIXct[1:2], format: "2024-04-24 15:02:37" "2024-04-24 15:01:37"
str(dplyr::bind_rows(df_list))
#> tibble [2 × 2] (S3: tbl_df/tbl/data.frame)
#>  $ dates_lt: POSIXct[1:2], format: "2024-04-24 15:02:37" "2024-04-24 15:01:37"
#>  $ dates_ct: POSIXct[1:2], format: "2024-04-24 15:02:37" "2024-04-24 15:01:37"
str(vctrs::vec_rbind(!!!df_list))
#> tibble [2 × 2] (S3: tbl_df/tbl/data.frame)
#>  $ dates_lt: POSIXct[1:2], format: "2024-04-24 15:02:37" "2024-04-24 15:01:37"
#>  $ dates_ct: POSIXct[1:2], format: "2024-04-24 15:02:37" "2024-04-24 15:01:37"
@DavisVaughan
Copy link
Member

DavisVaughan commented Apr 24, 2024

We push very hard towards POSIXct over POSIXlt, because the internal representation of POSIXlt is quite convoluted and memory heavy. See also #1576 (comment).

We made a design decision long ago that <POSIXlt> + <POSIXlt> = <POSIXct> is the best way to push the more "standard" date-time class of POSIXct, even if that feels slightly weird from a purity standpoint.

If you really really want to avoid that, then you will likely have to use something other than vctrs or the tooling that builds on it to retain POSIXlt.

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

No branches or pull requests

2 participants