Skip to content

Commit

Permalink
Convert NaN to NA in metric returns (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemahoney218 committed Apr 30, 2024
1 parent 14591d9 commit 04d6dc0
Show file tree
Hide file tree
Showing 10 changed files with 2,575 additions and 3,401 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# waywiser (development version)

* Metric functions now return `NA` in all cases where they previously returned `NaN`.
This improves cross-platform consistency; in particular, MacOS often returned
`NA` when every other platform would return `NaN`. (#63)

* `ww_multi_scale()` now handles classification and class probability metrics better
when called with raster arguments (either to `data` or to `truth` and `estimate`):
* When called with classification metrics, `ww_multi_scale()` will now convert
Expand Down
6 changes: 5 additions & 1 deletion R/misc_yardstick.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ yardstick_df <- function(data, truth, estimate, na_rm, name, metric_fun, ..., ca
sf::st_geometry(out) <- NULL
}

out[[".estimate"]][is.nan(out[[".estimate"]])] <- NA

out
}

Expand Down Expand Up @@ -198,7 +200,9 @@ yardstick_vec <- function(truth, estimate, na_rm, impl, wt = NULL, ..., case_wei
if (length(truth) == 0) rlang::abort("0 non-missing values were passed to `truth`.")
if (length(estimate) == 0) rlang::abort("0 non-missing values were passed to `estimate`.")

impl(truth = truth, estimate = estimate, ...)
out <- impl(truth = truth, estimate = estimate, ...)
out[is.nan(out)] <- NA
out
}

#' Workhorse function powering spatial yardstick metrics
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/srr-ww_global_geary_c.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
ww_global_geary_c_vec(worldclim_simulation$response, worldclim_simulation$
response, worldclim_weights)
Output
[1] NaN
[1] NA

---

Expand All @@ -174,7 +174,7 @@
# A tibble: 1 x 3
.metric .estimator .estimate
<chr> <chr> <dbl>
1 global_geary_c standard NaN
1 global_geary_c standard NA

# other generic srr standards

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/srr-ww_global_moran_i.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
ww_global_moran_i_vec(worldclim_simulation$response, worldclim_simulation$
response, worldclim_weights)
Output
[1] NaN
[1] NA

---

Expand All @@ -174,7 +174,7 @@
# A tibble: 1 x 3
.metric .estimator .estimate
<chr> <chr> <dbl>
1 global_moran_i standard NaN
1 global_moran_i standard NA

# other generic srr standards

Expand Down
993 changes: 427 additions & 566 deletions tests/testthat/_snaps/srr-ww_local_geary_c.md

Large diffs are not rendered by default.

993 changes: 427 additions & 566 deletions tests/testthat/_snaps/srr-ww_local_geary_pvalue.md

Large diffs are not rendered by default.

993 changes: 427 additions & 566 deletions tests/testthat/_snaps/srr-ww_local_getis_ord_g.md

Large diffs are not rendered by default.

993 changes: 427 additions & 566 deletions tests/testthat/_snaps/srr-ww_local_getis_ord_g_pvalue.md

Large diffs are not rendered by default.

993 changes: 427 additions & 566 deletions tests/testthat/_snaps/srr-ww_local_moran_i.md

Large diffs are not rendered by default.

993 changes: 427 additions & 566 deletions tests/testthat/_snaps/srr-ww_local_moran_pvalue.md

Large diffs are not rendered by default.

0 comments on commit 04d6dc0

Please sign in to comment.