NOAA-OWP / hydrotools

Suite of tools for retrieving USGS NWIS observations and evaluating National Water Model (NWM) data.
Other
53 stars 12 forks source link

Metrics: Default to numpy scalars for computation #163

Closed jarq6c closed 2 years ago

jarq6c commented 2 years ago

External testing found that attempting to compute categorical metrics using contingency tables with zero-valued components resulted in a ZeroDivision error. This behavior was undesirable for downstream users and inconsistent with the behavior of other packages used by hydrotools. This update introduces conversion of contingency table components to numpy.float64 scalars. This has the advantage of inheriting all of the numpy built-in value checking, including raising a RuntimeWarning in the event of division by zero, instead of raising an error.

Additions

Removals

Changes

Testing

  1. Explicit tests with null or zero-valued contingency table components
  2. Adding test scenarios for null or zero-valued continuous metrics
  3. convert_mapping_values is specifically tested using a pandas.Series

Notes

Todos

Checklist

jarq6c commented 2 years ago

Related to an issue originally reported by @RossWolford-NOAA

jarq6c commented 2 years ago

Took me a sec to see what the before and after of convert_mapping_values was gonna be, but it seems pretty good to me.

Thanks for the review!