vctrs icon indicating copy to clipboard operation
vctrs copied to clipboard

vec_is(..., new_datetime()) too strict

Open krlmlr opened this issue 4 years ago • 7 comments

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.

krlmlr avatar Mar 11 '20 05:03 krlmlr

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

DavisVaughan avatar Mar 11 '20 15:03 DavisVaughan

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.

lionel- avatar Mar 12 '20 08:03 lionel-

Can we treat types equal if their proxies are equal?

krlmlr avatar Mar 12 '20 14:03 krlmlr

We can't, e.g. factors and integers have the same memory representation but represent different values.

lionel- avatar Mar 13 '20 02:03 lionel-

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)

krlmlr avatar Mar 18 '21 06:03 krlmlr

This is probably incidental. vec_is() is currently not guaranteed to work this way, it has design issues that are not solved yet.

lionel- avatar Mar 18 '21 07:03 lionel-

Let's add a test while it lasts :zany_face:

krlmlr avatar Mar 18 '21 10:03 krlmlr