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

Dates should use double type #357

Closed
jennybc opened this issue Feb 2, 2016 · 0 comments
Closed

Dates should use double type #357

jennybc opened this issue Feb 2, 2016 · 0 comments
Assignees

Comments

@jennybc
Copy link
Member

@jennybc jennybc commented Feb 2, 2016

This is really esoteric but caused a test of mine to fail in a very puzzling way. Dates created by readr are different from those created all other ways (integer vs double).

library(readr)
xbase <- data.frame(d = as.Date(c("2016-02-02", NA)))
xdplyr <- dplyr::data_frame(d = as.Date(c("2016-02-02", NA)))
xreadr <- read_csv("d\n2016-02-02\nNA")

These appear to be the same, up to tbl_df-ness.

str(xbase)
#> 'data.frame':    2 obs. of  1 variable:
#>  $ d: Date, format: "2016-02-02" NA
str(xdplyr)
#> Classes 'tbl_df', 'tbl' and 'data.frame':    2 obs. of  1 variable:
#>  $ d: Date, format: "2016-02-02" NA
str(xreadr)
#> Classes 'tbl_df', 'tbl' and 'data.frame':    2 obs. of  1 variable:
#>  $ d: Date, format: "2016-02-02" NA

But the readr product stores its dates as integer vs numeric for the other two.

dput(xbase[2, , drop = FALSE])
#> structure(list(d = structure(NA_real_, class = "Date")), .Names = "d", row.names = 2L, class = "data.frame")
dput(xdplyr[2, ])
#> structure(list(d = structure(NA_real_, class = "Date")), .Names = "d", class = c("tbl_df", 
#> "data.frame"), row.names = c(NA, -1L))
dput(xreadr[2, ])
#> structure(list(d = structure(NA_integer_, class = "Date")), .Names = "d", class = c("tbl_df", 
#> "data.frame"), row.names = c(NA, -1L))

And it means even testthat::expect_equivalent() fails.

testthat::expect_equivalent(xdplyr, xreadr)
#> Error: xdplyr not equal to expected
#> Rows in x but not y: 2. Rows in y but not x: 2.
@hadley hadley changed the title representing dates with integer vs double Dates should use double type Jun 1, 2016
@jimhester jimhester self-assigned this Jun 7, 2016
@jimhester jimhester closed this Jun 7, 2016
@jimhester jimhester reopened this Jun 7, 2016
@lock lock bot locked and limited conversation to collaborators Sep 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants