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 #2

Closed
SymbolixAU opened this issue Sep 24, 2018 · 3 comments
Closed

Dates #2

SymbolixAU opened this issue Sep 24, 2018 · 3 comments
Labels
help wanted Extra attention is needed
Milestone

Comments

@SymbolixAU
Copy link
Collaborator

SymbolixAU commented Sep 24, 2018

Dates treated as numeric or character?

Numeric : more speed
Character : human-readable

jsonify::to_json( data.frame(dte = as.Date("2018-01-01") ) )
# [1] "[{\"dte\":17532.0}]"

jsonify::to_json( jsonify:::handle_dates( data.frame(dte = as.Date("2018-01-01") ) ) )
# [1] "[{\"dte\":\"2018-01-01\"}]"

n <- 1e6
df <- data.frame(id = 1:n, dte = sample(seq(as.Date("2018-01-01"), as.Date("2018-01-31"), length.out = n)))

library(microbenchmark)
microbenchmark(
  numeric = {
    jsonify::to_json( df )
  },
  character ={
    jsonify::to_json( jsonify:::handle_dates( df ) )
  },
  times = 5
)
# Unit: milliseconds
#      expr       min       lq     mean   median       uq      max neval
#   numeric  982.7153 1113.085 1117.633 1140.885 1149.160 1202.320     5
# character 4802.2583 4829.550 5130.051 4916.636 5146.547 5955.265     5

Decision

  • always numeric
  • always character
  • date_as_numeric = TRUE argument in to_json(). If FALSE, use handle_dates()
@SymbolixAU SymbolixAU added the help wanted Extra attention is needed label Sep 24, 2018
@SymbolixAU SymbolixAU self-assigned this Sep 24, 2018
@SymbolixAU SymbolixAU added this to the v0.1.0 milestone Sep 24, 2018
@SymbolixAU
Copy link
Collaborator Author

I'm leaning towards the quickest option as the default, so leaving Dates as numeric, but providing the dates_as_numeric (or similarly named) argument.

@SymbolixAU
Copy link
Collaborator Author

Given this issue & correction , need a robust solution for lists too.

@SymbolixAU
Copy link
Collaborator Author

I'm not going to support numeric_dates in lists for v0.1.0.

@sheffe sheffe mentioned this issue Feb 5, 2020
5 tasks
@SymbolixAU SymbolixAU removed their assignment Jan 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

0 participants