vctrs
vctrs copied to clipboard
vec_is(..., new_datetime()) too strict
The tzone
attribute is set for Sys.time()
but not for new_datetime()
, this is treated as a meaningful difference.
vctrs::vec_is(Sys.time(), vctrs::new_datetime())
#> [1] FALSE
Created on 2020-03-11 by the reprex package (v0.3.0)
Related: #561.
This strictness is part of the reason we have "partial" types. i.e. for factors the partial type "learns" the levels from the other input
library(vctrs)
vec_is(factor("x"), factor())
#> [1] FALSE
vec_is(factor("x"), partial_factor())
#> [1] TRUE
vec_is(factor("x"), factor("x"))
#> [1] TRUE
Created on 2020-03-11 by the reprex package (v0.3.0)
I'm not sure what the best long term solution is here though. It might be something other than partial types
To me this doesn't feel connected to partial types because I see timezone as a "detail" parameter of the type.
I think we'll need to bite the bullet and introduce a new generic for the is-a relationship.
Can we treat types equal if their proxies are equal?
We can't, e.g. factors and integers have the same memory representation but represent different values.
I now see:
vctrs::vec_is(Sys.time(), vctrs::new_datetime())
#> [1] TRUE
Created on 2021-03-18 by the reprex package (v1.0.0)
This is probably incidental. vec_is()
is currently not guaranteed to work this way, it has design issues that are not solved yet.
Let's add a test while it lasts :zany_face: