vctrs icon indicating copy to clipboard operation
vctrs copied to clipboard

`vec_c()` should probably cast `xs` to a common type before handing off to `df_c_fallback()`

Open DavisVaughan opened this issue 9 months ago • 2 comments

From https://github.com/tidyverse/tidyr/issues/1507

Also ensure we fix it in list_unchop() too!

See the 1970-01-02?

library(tibble)
library(data.table)
library(vctrs)

xs <- list(
  tibble(x = as.IDate('2012-01-01')),
  tibble(y = 1)
)

vec_c(!!!xs)
#> # A tibble: 2 × 2
#>   x              y
#>   <IDate>    <dbl>
#> 1 2012-01-01    NA
#> 2 1970-01-02     1

# fallback class, so actual combination for this `x` column
# is delayed until `df_c_fallback()`
vctrs:::vec_ptype_common_fallback(!!!xs)
#> # A tibble: 0 × 2
#> # ℹ 2 variables: x <vct:::__>, y <dbl>

# but `df_c_fallback()` gets the _original_ `xs`, not the `xs` after they
# have been cast to a common type! so when it `list_pluck()`s out the 1st column,
# it takes `xs[[1]][[1]]` and `xs[[2]][[1]]` (i.e. the x column of the 1st
# element and the y column of the 2nd element).

# you can prove that it works if you go ahead and pre cast them to a common type
vec_c(!!!vec_cast_common(!!!xs))
#> # A tibble: 2 × 2
#>   x              y
#>   <IDate>    <dbl>
#> 1 2012-01-01    NA
#> 2 NA             1

DavisVaughan avatar Nov 02 '23 13:11 DavisVaughan