Skip to content

Commit

Permalink
[558] fix for cases where enumerated types used inaccurate comparison…
Browse files Browse the repository at this point in the history
… operators
  • Loading branch information
monocongo committed Sep 17, 2024
1 parent c561111 commit 42c67c2
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/climate_indices/indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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"]
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 42c67c2

Please sign in to comment.