Skip to content

Commit

Permalink
add warning
Browse files Browse the repository at this point in the history
  • Loading branch information
RondeauG committed Sep 10, 2024
1 parent b771ef8 commit 7438687
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/xscen/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,11 @@ def translate_time_chunk(chunks: dict, calendar: str, timesize: int) -> dict:
"all_leap": 366,
"366_day": 366,
}.get(calendar, 365.25)
if nt != int(nt):
warnings.warn(
f"The number of days in {chunks['time']} for calendar {calendar} is not an integer. "
f"Chunks will not align perfectly with year ends."
)
chunks[k] = int(nt)
elif v == -1:
chunks[k] = timesize
Expand Down
6 changes: 6 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ def test_ny(self, calendar):
)
assert out == {"time": ndays * 4, "lon": 50}

def test_warning(self):
with pytest.warns(UserWarning, match="The number of days"):
xs.utils.translate_time_chunk(
{"time": "3years", "lon": 50}, "standard", 3450
)

def test_dict_of_dict(self):
out = xs.utils.translate_time_chunk(
{"tas": {"time": 10, "lon": 50}, "pr": {"time": -1, "lon": 50}},
Expand Down

0 comments on commit 7438687

Please sign in to comment.