Skip to content

Commit

Permalink
Fix bug mixing integer fill values and float data types
Browse files Browse the repository at this point in the history
  • Loading branch information
grimbough committed Sep 26, 2024
1 parent 8562011 commit 4be7ec3
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions R/read_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,27 @@ read_array_metadata <- function(path, s3_client = NULL) {
#'
#' @keywords Internal
update_fill_value <- function(metadata) {
val <- metadata$fill_value
datatype <- .parse_datatype(metadata$dtype)
## a null fill value implies no missing values.
## We set to NA as you can't create an array of NULL in R
if (is.null(metadata$fill_value)) {
if (is.null(val)) {
metadata$fill_value <- NA
} else if (metadata$fill_value %in% c("NaN", "Infinity", "-Infinity")) {
datatype <- .parse_datatype(metadata$dtype)
} else if (val %in% c("NaN", "Infinity", "-Infinity")) {
if (datatype$base_type != "string") {
metadata$fill_value <- switch(metadata$fill_value,
metadata$fill_value <- switch(val,
"NaN" = NaN,
"Infinity" = Inf,
"-Infinity" = -Inf
)
}
} else if (is.numeric(metadata$fill_value)) {
metadata$fill_value <- switch(datatype$base_type,
"float" = as.double(val),
"int" = as.integer(val),
"uint" = as.integer(val),
"complex" = as.complex(val))

}
return(metadata)
}
Expand Down

0 comments on commit 4be7ec3

Please sign in to comment.