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

all.equal.tbl_df should return TRUE for tbl_df with Date column #1204

Closed
jullybobble opened this issue Jun 7, 2015 · 3 comments
Closed

all.equal.tbl_df should return TRUE for tbl_df with Date column #1204

jullybobble opened this issue Jun 7, 2015 · 3 comments
Assignees
Milestone

Comments

@jullybobble
Copy link

a is a data.frame with a Date column.

a <- data.frame(date = as.Date("2015-06-07"))

When serialised and deserialised with readr's write_csv and read_csv, the resulting data.frame b_tbl is equal to a according to base:::all.equal.default, but not according to dplyr:::all.equal.tbl_df:

b_tbl <- readr::read_csv(readr::write_csv(a, path = ""))
b <- dplyr:::as.data.frame.tbl_df(b_tbl)
a_tbl <- dplyr:::as.tbl(a)

dplyr:::all.equal.tbl_df(a_tbl, b_tbl)
# "Incompatible type for column date: x Date, y Date"

base:::all.equal.default(a_tbl, b_tbl) 
# TRUE

base:::all.equal.default(a, b)
 # TRUE

dplyr:::all.equal.tbl_df(a, b)
# "Incompatible type for column date: x Date, y Date"

I would expect all 4 all.equal statements above to return TRUE.

Note that this occurs only if b_tbl is the result of a write_csv and read_csv, so I am not sure whether the issue is related to readr or dplyr, but the inconsistency shows in dplyr:

dplyr:::all.equal.tbl_df(a_tbl, a)
# TRUE
@romainfrancois
Copy link
Member

Hmm. The issue is that for some reason the Date in a is encoded as a numeric instead of an integer :

> .Internal(inspect(( a_tbl$date )))
@7f87e3e990c8 14 REALSXP g0c1 [OBJ,MARK,NAM(2),ATT] (len=1, tl=0) 16593
ATTRIB:
  @7f87e3a3db48 02 LISTSXP g0c0 [MARK]
    TAG: @7f87f2006148 01 SYMSXP g1c0 [MARK,NAM(2),LCK,gp=0x4000] "class" (has value)
    @7f87e3e99098 16 STRSXP g0c1 [MARK,NAM(2)] (len=1, tl=0)
      @7f87f21f18a8 09 CHARSXP g1c1 [MARK,gp=0x61] [ASCII] [cached] "Date"
> .Internal(inspect(( b_tbl$date )))
@7f87f6e20cb8 13 INTSXP g0c1 [OBJ,NAM(2),ATT] (len=1, tl=0) 16593
ATTRIB:
  @7f87f3b181f8 02 LISTSXP g0c0 []
    TAG: @7f87f2006148 01 SYMSXP g1c0 [MARK,NAM(2),LCK,gp=0x4000] "class" (has value)
    @7f87f6e20d18 16 STRSXP g0c1 [NAM(2)] (len=1, tl=0)
      @7f87f21f18a8 09 CHARSXP g1c1 [MARK,gp=0x61] [ASCII] [cached] "Date"

@hadley
Copy link
Member

hadley commented Aug 13, 2015

@romainfrancois sometimes dates are numerics and sometimes they're integers :/

@romainfrancois
Copy link
Member

Yes apparently. I'll come up with a workaround.

@romainfrancois romainfrancois self-assigned this Aug 14, 2015
@romainfrancois romainfrancois added this to the 0.5 milestone Aug 14, 2015
krlmlr pushed a commit to krlmlr/dplyr that referenced this issue Mar 2, 2016
…teger

  and numeric), making e.g `all.equal` more resistant. closes tidyverse#1204.
@lock lock bot locked as resolved and limited conversation to collaborators Jun 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants