Skip to content

Commit

Permalink
[187773038]: take out type information when updating NA
Browse files Browse the repository at this point in the history
  • Loading branch information
gergness committed Jun 12, 2024
1 parent 538554d commit 9babe3e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
9 changes: 3 additions & 6 deletions R/variable-update.R
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ setMethod(
function(x, i, j, value) {
if (all(is.na(value))) {
## For assigning NA
value <- .no.data.value(type(x), add.type = TRUE)
value <- .no.data.value(type(x))
if (has.categories(x)) {
return(.categorical.update[["numeric"]](x, i, j, value))
}
Expand All @@ -266,14 +266,11 @@ setMethod(
}
)

.no.data.value <- function(x, add.type = FALSE) {
.no.data.value <- function(x) {
if (has.categories(x)) {
return(NA)
} else {
out <- NA
if (add.type) {
out <- list(value = NA, type = list(class = x))
}
out <- list(value = NA)
return(out)
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-update-with-missing.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ with_mock_crunch({
expect_POST(
is.na(ds$birthyr) <- ds$birthyr > 2016,
"https://app.crunch.io/api/datasets/1/table/", '{"command":"update","variables":',
'{"https://app.crunch.io/api/datasets/1/variables/birthyr/":{"value":null,',
'"type":{"class":"numeric"}}},"filter":{"function":">","args":',
'{"https://app.crunch.io/api/datasets/1/variables/birthyr/":{"value":null',
'}},"filter":{"function":">","args":',
'[{"variable":"https://app.crunch.io/api/datasets/1/variables/birthyr/"},',
'{"value":2016}]}}'
)
Expand Down

0 comments on commit 9babe3e

Please sign in to comment.