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_ptype() materializes date, time, and logical vectors #1956

Open
krlmlr opened this issue Oct 23, 2024 · 0 comments
Open

vec_ptype() materializes date, time, and logical vectors #1956

krlmlr opened this issue Oct 23, 2024 · 0 comments

Comments

@krlmlr
Copy link
Member

krlmlr commented Oct 23, 2024

I thought that getting the ptype should be possible without accessing the vector. This currently fails for date, time, and logical columns.

Important for duckplyr because we want to do things differently depending on the column type but without materializing. I can work around if I must, ideally, I'd just rely on vctrs.

CC @hannes.

options(conflicts.policy = list(warn = FALSE))
library(duckplyr)
#> ✔ Overwriting dplyr methods with duckplyr methods.
#> ℹ Turn off with `duckplyr::methods_restore()`.

Sys.setenv(DUCKPLYR_FORCE = TRUE)

data.frame(a = Sys.Date()) |>
  pull() |>
  vctrs::vec_ptype()
#> materializing:
#> ---------------------
#> --- Relation Tree ---
#> ---------------------
#> Projection [a as a]
#>   r_dataframe_scan(0x150fb1fb0)
#> 
#> ---------------------
#> -- Result Columns  --
#> ---------------------
#> - a (DATE)
#> Date of length 0

data.frame(a = clock::date_time_set_zone(Sys.time(), "UTC")) |>
  pull() |>
  vctrs::vec_ptype()
#> materializing:
#> ---------------------
#> --- Relation Tree ---
#> ---------------------
#> r_dataframe_scan(0x130efe8b0)
#> 
#> ---------------------
#> -- Result Columns  --
#> ---------------------
#> - a (TIMESTAMP)
#> 
#> materializing:
#> ---------------------
#> --- Relation Tree ---
#> ---------------------
#> Projection [a as a]
#>   r_dataframe_scan(0x130efe8b0)
#> 
#> ---------------------
#> -- Result Columns  --
#> ---------------------
#> - a (TIMESTAMP)
#> POSIXct of length 0

data.frame(a = FALSE) |>
  pull() |>
  vctrs::vec_ptype()
#> materializing:
#> ---------------------
#> --- Relation Tree ---
#> ---------------------
#> Projection [a as a]
#>   r_dataframe_scan(0x127b87498)
#> 
#> ---------------------
#> -- Result Columns  --
#> ---------------------
#> - a (BOOLEAN)
#> logical(0)

data.frame(a = 1) |>
  pull() |>
  vctrs::vec_ptype()
#> numeric(0)

data.frame(a = 1L) |>
  pull() |>
  vctrs::vec_ptype()
#> integer(0)

data.frame(a = "x") |>
  pull() |>
  vctrs::vec_ptype()
#> character(0)

Created on 2024-10-23 with reprex v2.1.1

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

1 participant