diff --git a/src/xscen/utils.py b/src/xscen/utils.py index 671dbeb2..08428cfd 100644 --- a/src/xscen/utils.py +++ b/src/xscen/utils.py @@ -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 diff --git a/tests/test_utils.py b/tests/test_utils.py index b52e857a..00a09a8a 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -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}},