Skip to content

Commit d04e4af

Browse files
authored
Merge pull request #244 from cmu-delphi/ds/covid-hosp-na-bug
fix: NAs in int field bug
2 parents d39bd25 + 539e958 commit d04e4af

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Imports:
3939
tibble,
4040
usethis,
4141
xml2
42-
RoxygenNote: 7.3.0
42+
RoxygenNote: 7.3.1
4343
Suggests:
4444
dplyr,
4545
ggplot2,

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
- Fix some errors from passing "" as a key.
2323
- `pvt_twitter` and `pub_wiki` now use `time_type` and `time_values` args instead of mutually exclusive `dates` and `epiweeks` (#236). This matches the interface of the `pub_covidcast` endpoint.
2424
- All endpoints now support the use of "\*" as a wildcard to fetch all dates or epiweeks (#234).
25+
- Fixed bug with NAs when parsing ints (#243).
2526

2627
# epidatr 1.0.0
2728

R/model.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ parse_value <- function(info, value, disable_date_parsing = FALSE) {
179179
} else if (info$type == "int") {
180180
# Int doesn't have enough capacity to store some weekly `pub_wiki` values.
181181
value <- as.double(value)
182-
if (any(value != round(value))) {
182+
if (any(na.omit(value != round(value)))) {
183183
cli::cli_warn(
184184
c(
185185
"Values in {info$name} were expected to be integers but contain a decimal component",

tests/testthat/test-model.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@ test_that("parse_data_frame warns when df contains int values with decimal compo
123123
)
124124
})
125125

126+
test_that("parse_value can handle NA/NULL values in an int field", {
127+
info <- create_epidata_field_info(
128+
name = "test",
129+
type = "int"
130+
)
131+
expect_warning(
132+
parse_value(info, c(1, 1.5, NA, NULL)),
133+
class = "epidatr__int_nonzero_decimal_digits"
134+
)
135+
})
136+
126137
test_that("parse_api_date accepts str and int input", {
127138
expect_identical(parse_api_date("20200101"), as.Date("2020-01-01"))
128139
expect_identical(parse_api_date(20200101), as.Date("2020-01-01"))

0 commit comments

Comments
 (0)