Skip to content

Commit

Permalink
Merge pull request #260 from cmu-delphi/ndefries/nchs-week-parsing
Browse files Browse the repository at this point in the history
Get NCHS mortality to fetch data by changing expected date col output type to `epiweek`
  • Loading branch information
nmdefries authored Mar 4, 2024
2 parents 1356f60 + 327d7fc commit fe42abc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: epidatr
Type: Package
Title: Client for Delphi's 'Epidata' API
Version: 1.1.1
Version: 1.1.2
Authors@R:
c(
person("Logan", "Brooks", email = "[email protected]", role = c("aut")),
Expand Down
6 changes: 4 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
## Features

## Patches
- Fixed failure when passing `as_of` values in `Date` format to
`pub_covidcast` while caching is enabled (#259)
- Fix failure when passing `as_of` values in `Date` format to
`pub_covidcast` while caching is enabled (#259).
- For `pub_covidcast` data source `nchs-mortality`, parse dates as `epiweek`
and expect `epiweek` inputs from user (#260).

# epidatr 1.1.0

Expand Down
17 changes: 15 additions & 2 deletions R/endpoints.R
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,13 @@ pub_covidcast <- function(
as_of <- parse_timeset_input(as_of)
issues <- parse_timeset_input(issues)

if (source == "nchs-mortality" && time_type != "week") {
cli::cli_abort(
"{source} data is only available at the week level",
class = "epidatr__nchs_week_only"
)
}

create_epidata_call(
"covidcast/",
list(
Expand All @@ -1051,8 +1058,14 @@ pub_covidcast <- function(
c("day", "week")
),
create_epidata_field_info("geo_value", "text"),
create_epidata_field_info("time_value", "date"),
create_epidata_field_info("issue", "date"),
create_epidata_field_info("time_value", switch(time_type,
day = "date",
week = "epiweek"
)),
create_epidata_field_info("issue", switch(time_type,
day = "date",
week = "epiweek"
)),
create_epidata_field_info("lag", "int"),
create_epidata_field_info("value", "float"),
create_epidata_field_info("stderr", "float"),
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test-endpoints.R
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,14 @@ test_that("pub_covid_hosp_state_timeseries supports versioned queries", {
expect_identical(epidata_call$params$as_of, 20220101)
expect_identical(epidata_call$params$lag, NULL)
})

test_that("nchs-mortality call fails if time_type not week", {
expect_error(pub_covidcast(
source = "nchs-mortality",
signals = "signal",
time_type = "day",
geo_type = "state",
time_values = "*",
geo_values = "*"
), class = "epidatr__nchs_week_only")
})

0 comments on commit fe42abc

Please sign in to comment.