Skip to content

Commit

Permalink
refactor: remove deprecated typing alias' for builtins and collection…
Browse files Browse the repository at this point in the history
…s.abc
  • Loading branch information
Aidan Griffiths authored and tennlee committed Oct 19, 2023
1 parent fbd66eb commit beb0da5
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 20 deletions.
19 changes: 7 additions & 12 deletions src/scores/categorical/multicategorical_impl.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""
This module contains methods which may be used for scoring multicategorical forecasts
"""
from typing import Optional, Sequence, Union
from collections.abc import Sequence
from typing import Optional, Union

import numpy as np
import xarray as xr

from scores.functions import apply_weights
from scores.utils import check_dims, dims_complement, gather_dimensions
from scores.utils import check_dims, gather_dimensions


def firm(
Expand All @@ -19,7 +20,7 @@ def firm(
discount_distance: Optional[float] = 0,
reduce_dims: Optional[Sequence[str]] = None,
preserve_dims: Optional[Sequence[str]] = None,
weights: Optional[xr.DataArray]=None
weights: Optional[xr.DataArray] = None,
) -> xr.Dataset:
"""
Calculates the FIxed Risk Multicategorical (FIRM) score including the
Expand Down Expand Up @@ -105,14 +106,10 @@ def firm(
)
total_score = []
for categorical_threshold, weight in zip(categorical_thresholds, threshold_weights):
score = weight * _single_category_score(
fcst, obs, risk_parameter, categorical_threshold, discount_distance
)
score = weight * _single_category_score(fcst, obs, risk_parameter, categorical_threshold, discount_distance)
total_score.append(score)
summed_score = sum(total_score)
reduce_dims = gather_dimensions(
fcst.dims, obs.dims, reduce_dims, preserve_dims
)
reduce_dims = gather_dimensions(fcst.dims, obs.dims, reduce_dims, preserve_dims)
summed_score = apply_weights(summed_score, weights)
score = summed_score.mean(dim=reduce_dims)

Expand All @@ -133,9 +130,7 @@ def _check_firm_inputs(
raise ValueError("`categorical_thresholds` must have at least one threshold")

if not len(categorical_thresholds) == len(threshold_weights):
raise ValueError(
"The length of `categorical_thresholds` and `weights` must be equal"
)
raise ValueError("The length of `categorical_thresholds` and `weights` must be equal")
if risk_parameter <= 0 or risk_parameter >= 1:
raise ValueError("0 < `risk_parameter` < 1 must be satisfied")

Expand Down
3 changes: 2 additions & 1 deletion src/scores/continuous/murphy_impl.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""
Murphy score
"""
from typing import Literal, Optional, Sequence, Union
from collections.abc import Sequence
from typing import Literal, Optional, Union

import numpy as np
import xarray as xr
Expand Down
4 changes: 2 additions & 2 deletions src/scores/probability/crps_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
This module supports the implementation of the CRPS scoring function, drawing from additional functions.
The primary method, `crps_cdf` is imported into the probability module to be part of the probability API
"""

from typing import Iterable, Literal, Optional
from collections.abc import Iterable
from typing import Literal, Optional

import numpy as np
import pandas as pd
Expand Down
4 changes: 2 additions & 2 deletions src/scores/probability/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
This module contains a variety of functions which modify data in various ways to process data structures
to support probablistic verification.
"""

from typing import Iterable, Literal, Optional
from collections.abc import Iterable
from typing import Literal, Optional

import numpy as np
import pandas as pd
Expand Down
4 changes: 2 additions & 2 deletions src/scores/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
This module contains various compound or union types which can be used across the codebase to ensure
a consistent approach to typing is handled.
"""

from typing import Hashable, Iterable, Optional, Union
from collections.abc import Hashable, Iterable
from typing import Optional, Union

import pandas as pd
import xarray as xr
Expand Down
3 changes: 2 additions & 1 deletion src/scores/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
Contains frequently-used functions of a general nature within scores
"""
import warnings
from typing import Hashable, Iterable, List, Optional
from collections.abc import Hashable, Iterable
from typing import Optional

import xarray as xr

Expand Down

0 comments on commit beb0da5

Please sign in to comment.