-
Notifications
You must be signed in to change notification settings - Fork 5
Consolidate fetch
interfaces
#99
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
Conversation
* add a universal fetch interface that calls fetch_classic or fetch_json * test and compare fetch_tbl and fetch_csv * deprecate and unexport fetch_csv, fetch_json * redo documentation and vignettes * export as_tibble * add mockery and mockr to Suggests
* Favor `expect_identical` over `expect_equal`, as `expect_identical` is stricter, though in testthat edition 3.0, not as strict as `identical`. * Avoid `dplyr::all_equal`, which was even more (and excessively) lenient and is now deprecated.
* Remove description of nonexistent parameter. * Apply some markdown formatting.
* Keep developers' .Renviron's from interfering with the auth tests. * Add test characterizing how we have the env var take precedence over the option.
so that the "Value:" heading in the documentation will appear as a bulleted list naming each function documented in this topic and what its return value looks like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- praise: interface is looking more streamlined and slimmer
- praise: looks like people can't miss epidata errors now!
- issue: need to warn on epidata warnings in message.
-
todo: figure out whether epidata statuses or http statuses should be checked first. (see API keys doc for key situation. another one is when results are truncated, especially in older endpoints where the limits may be very small; maybe this should actually be an error because there's not a clear bug-free way to take advantage of any of the results, unless someone just wanted a preview, but then they could/should just ask for less data)[if there is http error, there will not be an epidata status; the content will be html with an error message] - question: what is return code 2? is that for truncated results?
- todo: fix "1 for success, non-zero for failure"
- [transferred below] question: (answer depends on some of the above questions/changes) what's the idea for
fetch_classic()
regarding errors and warnings? Right now it seems like a kind of mixed thing that stops in some cases, but still returns status&message info when it succeeds. Can we make it more consistent? (E.g., try to stop on all errors, warn on all warnings, and return$epidata
?) - suggestion: rename "
method = c("data.frame", "csv")
to something like "via = c("classic", "csv")
orencoding = c("classic", "csv")
- question: is "fixtures" a standard term for these test prototype objects?
testthat
docs seem to use "fixture" to refer tolocal_*()
functions - issue: (potentially; might be server thing)
delphi(system = "ec", epiweek = 202006) %>% fetch()
anddelphi(system = "ec", epiweek = 202006) %>% fetch_classic()
return 500s - question: Sorry, I'm so confused right now. I see in test comments and now code that "fetch_classic uses jsonlite::fromJSON, which converts the underlying data to a data.frame". But I thought we wanted this to give a nested list format on the only-classic things; we'd just want the old client's way of getting content for this function, and only use fromJSON when
fetch_tbl
-ing via the"classic"
transfer-format/encoding, right? Or am I misunderstanding whatfetch_classic
output-format is supposed to be now? - todo: clarify/fix "fetch_csv uses readr::read_csv"; I assume it's
fetch_tbl(...., format = "csv")
that does this
Stopping here because I'm confused and may just be writing unhelpful things at this point. I haven't given the test based on the fixture objects a good look through yet, think I'll just muddle things further.
- note: okay, now I see the
disable_data_frame_parsing
parameter. But I assume some statements I mentioned above may need clarified by mentioning this parameter or something along those lines. - note: I also committed a few minor changes to do with a dplyr deprecation and what I think current testthat practices are, roxygen tweaks, various wording tweaks
|
A couple error/warning cases I can think of:
|
Regarding fixtures: Thanks for the link. I had read some pytest fixture description before but it just sounded like testthat's definition, but now looking at examples, they do look more like fixed objects if you don't use extra features. Don't feel too strongly about the naming here, just hoped there was something more specific/clearer because just googling gave me a lot of context/intro and I couldn't quickly find just a simple definition. (Note that in testthat you can define objects in a test file outside calls to |
Sorry, the Will need to dig into server stuff to see if we send messages for truncated results. I have a hunch that this was a TODO item and currently we just truncate without warning. |
* `sort` and `arrange` will still deal with these in the same way * `print` will no longer have distracting (and untrue in some cases for `geo_type`, since we don't have a pure hierarchy) `<`'s * `contrasts` will output indicators for the 2nd--last levels, rather than something more complex; see https://colinfay.me/intro-to-r/statistical-models-in-r.html#Contrasts. We might also consider just plain character vectors for these two, to prevent certain completion utilities from doing some annoying things by default.
Add a test for this warning. Additionally, fix `mockery::stub` usage to do the intended thing for `fetch_tbl` in related tests; fix looks a little hacky, but stubbing with `depth = 2` within `fetch_tbl` didn't seem to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Made a few edits; please give them a sanity check / fixup.
@@ -108,25 +108,25 @@ print.covidcast_data_source <- function(source, ...) { | |||
#' @export | |||
covidcast_epidata <- function(base_url = global_base_url) { | |||
url <- join_url(base_url, "covidcast/meta") | |||
result <- do_request(url, list()) | |||
response <- do_request(url, list()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: These clarifications are great! When talking about these things, we should try to match this terminology, though we might need to also say "http response" or "epidata response" sometimes. Though I'm still going to mix up result and response for a while though.
# fetch_debug(format_type = "classic") %>% | ||
# readr::write_rds(testthat::test_path("data/test-classic.rds")) | ||
mockery::stub(fetch_classic, "httr::content", readRDS(testthat::test_path("data/test-classic.rds"))) | ||
mockery::stub(fetch_tbl, "fetch_classic", fetch_classic) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#' | ||
#' @export | ||
fetch_json <- function(epidata_call, fields = NULL, disable_date_parsing = FALSE) { | ||
fetch_csv <- function(epidata_call, fields = NULL, disable_date_parsing = FALSE, disable_tibble_output = FALSE) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: can we eliminate fetch_csv
altogether? Or is it used internally somewhere / otherwise desirable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can. I kept it around just so we had a test reference for the new fetch_tbl
.
Going to go ahead and merge this, so we have warnings and the new interface for API keys rollout. |
Change `fetch_tbl` -> `fetch`, following cmu-delphi/epidatr#99.
A list of changes:
fetch
function, which most of the time callsfetch_tbl
and callsfetch_classic
if the endpoint isonly_supports_classic
(this isdelphi
,pvt_norostat_meta
, andmeta
)fetch_tbl
now usesfetch_classic
to make requests (instead of CSV)fetch_csv
,fetch_classic
,fetch_tbl
fetch_json
fetch_debug
for response debuggingrequest_impl
now always raises on HTTP errors, forwards the HTML body to the errorfetch
always raises for epidata errors, including no resultsfetch_tbl
andfetch_csv
(identical on a few small queries)TODO:
fetch
interfacesFixes:
fetch_*
interfaces #72fetch_tbl()
warning fromvroom
sometimes (whenNA
's are present?) #106 (not sure how, might be related to switching away from readr::read_csv to jsonlite::fromJSON)