From 42c67c22c4eb7c795abdfde665ec3cfffdf88b26 Mon Sep 17 00:00:00 2001 From: James Adams Date: Tue, 17 Sep 2024 14:27:20 -0400 Subject: [PATCH 1/3] [558] fix for cases where enumerated types used inaccurate comparison operators --- src/climate_indices/indices.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/climate_indices/indices.py b/src/climate_indices/indices.py index 706147ab..6ee393e8 100644 --- a/src/climate_indices/indices.py +++ b/src/climate_indices/indices.py @@ -137,16 +137,15 @@ def spi( # by the specified number of time steps values = compute.sum_to_scale(values, scale) - # reshape precipitation values to (years, 12) for monthly, - # or to (years, 366) for daily - if periodicity is compute.Periodicity.monthly: + # reshape precipitation values to (years, 12) for monthly, or to (years, 366) for daily + if (periodicity == compute.Periodicity.monthly) or (periodicity == "monthly"): values = utils.reshape_to_2d(values, 12) - elif periodicity is compute.Periodicity.daily: + elif (periodicity == compute.Periodicity.daily) or (periodicity == "daily"): values = utils.reshape_to_2d(values, 366) else: - raise ValueError(f"Invalid periodicity argument: {periodicity}") + raise ValueError(f"Invalid periodicity argument: '{periodicity}'") - if distribution is Distribution.gamma: + if distribution == Distribution.gamma: # get (optional) fitting parameters if provided if fitting_params is not None: alphas = fitting_params["alpha"] @@ -166,7 +165,7 @@ def spi( alphas, betas, ) - elif distribution is Distribution.pearson: + elif distribution == Distribution.pearson: # get (optional) fitting parameters if provided if fitting_params is not None: probabilities_of_zero = fitting_params["prob_zero"] @@ -194,7 +193,7 @@ def spi( ) else: - message = f"Unsupported distribution argument: {distribution}" + message = f"Unsupported distribution argument: '{distribution}'" _logger.error(message) raise ValueError(message) From 7f6941a807b28b20b355e3f3f76dd3665f606c58 Mon Sep 17 00:00:00 2001 From: James Adams Date: Tue, 17 Sep 2024 15:08:23 -0400 Subject: [PATCH 2/3] [558] removed superfluous string comparisons --- src/climate_indices/indices.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/climate_indices/indices.py b/src/climate_indices/indices.py index 6ee393e8..7e3b152a 100644 --- a/src/climate_indices/indices.py +++ b/src/climate_indices/indices.py @@ -138,9 +138,9 @@ def spi( values = compute.sum_to_scale(values, scale) # reshape precipitation values to (years, 12) for monthly, or to (years, 366) for daily - if (periodicity == compute.Periodicity.monthly) or (periodicity == "monthly"): - values = utils.reshape_to_2d(values, 12) - elif (periodicity == compute.Periodicity.daily) or (periodicity == "daily"): + if periodicity == compute.Periodicity.monthly: + values = utils.reshape_to_2d(values, 12) + elif periodicity == compute.Periodicity.daily: values = utils.reshape_to_2d(values, 366) else: raise ValueError(f"Invalid periodicity argument: '{periodicity}'") From 52d69c18bf269823b4b7765e4af621c7b7069c24 Mon Sep 17 00:00:00 2001 From: James Adams Date: Tue, 17 Sep 2024 15:17:09 -0400 Subject: [PATCH 3/3] [558] removed superfluous string comparisons, replaced remaining periodicity checks from `is` to `==` --- src/climate_indices/indices.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/climate_indices/indices.py b/src/climate_indices/indices.py index 7e3b152a..a7f304c9 100644 --- a/src/climate_indices/indices.py +++ b/src/climate_indices/indices.py @@ -397,9 +397,9 @@ def percentage_of_normal( # if doing monthly then we'll use 12 periods, corresponding to calendar # months, if daily assume years w/366 days - if periodicity is compute.Periodicity.monthly: + if periodicity == compute.Periodicity.monthly: periodicity = 12 - elif periodicity is compute.Periodicity.daily: + elif periodicity == compute.Periodicity.daily: periodicity = 366 else: message = f"Invalid periodicity argument: '{periodicity}'"