Skip to content

Commit

Permalink
Update interval check in resample_hours (#2362)
Browse files Browse the repository at this point in the history
  • Loading branch information
axel-lauer authored Mar 18, 2024
1 parent 972150d commit a7586e8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion esmvalcore/preprocessor/_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,7 @@ def resample_hours(cube: Cube, interval: int, offset: int = 0) -> Cube:
f'the interval ({interval})')
time = cube.coord('time')
cube_period = time.cell(1).point - time.cell(0).point
if cube_period.total_seconds() / 3600 >= interval:
if cube_period.total_seconds() / 3600 > interval:
raise ValueError(f"Data period ({cube_period}) should be lower than "
f"the interval ({interval})")
hours = [PartialDateTime(hour=h) for h in range(0 + offset, 24, interval)]
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/preprocessor/_time/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -2082,8 +2082,9 @@ def test_resample_same_interval(self):
times = np.arange(0, 48, 12)
cube = self._create_cube(data, times)

with self.assertRaises(ValueError):
resample_hours(cube, interval=12)
result = resample_hours(cube, interval=12)
expected = np.arange(0, 48, 12)
assert_array_equal(result.data, expected)

def test_resample_nodata(self):
"""Test average of a 1D field."""
Expand Down

0 comments on commit a7586e8

Please sign in to comment.