Skip to content

Commit

Permalink
MAINT: Update SliceMode typing
Browse files Browse the repository at this point in the history
Now a Frequency instance can be used directly as a
valid input for `slice_mode`.
  • Loading branch information
bzah committed Apr 27, 2022
1 parent e7e9b6e commit a288fd3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 3 additions & 2 deletions icclim/models/frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

from icclim.icclim_exceptions import InvalidIcclimArgumentError

SliceMode = Union[str, List[Union[str, Tuple, int]]]


def seasons_resampler(
month_list: list[int],
Expand Down Expand Up @@ -232,3 +230,6 @@ def _get_frequency_from_list(slice_mode_list: list) -> Frequency:
"The sampling frequency must be one of {'season', 'month'}"
)
return custom_freq


SliceMode = Union[Frequency, str, List[Union[str, Tuple, int]]]
13 changes: 13 additions & 0 deletions icclim/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import icclim
from icclim.models.ecad_indices import EcadIndex
from icclim.models.frequency import Frequency
from icclim.models.index_group import IndexGroup


Expand Down Expand Up @@ -68,6 +69,18 @@ def test_index_SU(self):
)
np.testing.assert_array_equal(0, res.SU)

def test_index_SU__monthy_sampled(self):
res = icclim.index(
indice_name="SU",
in_files=self.data,
out_file=self.OUTPUT_FILE,
slice_mode=Frequency.MONTH,
)
np.testing.assert_array_equal(0, res.SU)
np.testing.assert_array_equal(
len(np.unique(self.TIME_RANGE.year)) * 12, len(res.time)
)

def test_indices_from_DataArray(self):
res = icclim.indices(
index_group=IndexGroup.HEAT, in_files=self.data, out_file=self.OUTPUT_FILE
Expand Down

0 comments on commit a288fd3

Please sign in to comment.