diff --git a/src/hflow/resample.py b/src/hflow/resample.py index 72565438..29242e65 100644 --- a/src/hflow/resample.py +++ b/src/hflow/resample.py @@ -28,6 +28,7 @@ import numpy as np +from hflow._field_guards import require_finite_float from hflow.format import NANOSECONDS_PER_SECOND if TYPE_CHECKING: @@ -238,6 +239,7 @@ def to_grid( pinned by ``hflow.format.RESAMPLE_POLICY_VERSION`` (see the module docstring). """ + rate_hz = require_finite_float(rate_hz, "rate_hz") if rate_hz <= 0.0: raise ValueError(f"rate_hz must be positive, got {rate_hz}") source_columns = _source_columns(channel, field) diff --git a/tests/test_resample_derive.py b/tests/test_resample_derive.py index 9fe877be..2d48a5f1 100644 --- a/tests/test_resample_derive.py +++ b/tests/test_resample_derive.py @@ -208,9 +208,19 @@ def test_to_grid_rejects_span_shorter_than_one_step() -> None: to_grid(ramp_channel(), 0.01, policy="interpolate") -def test_to_grid_rejects_nonpositive_rate() -> None: - with pytest.raises(ValueError, match="rate_hz must be positive"): - to_grid(ramp_channel(), 0.0, policy="interpolate") +@pytest.mark.parametrize( + ("rate_hz", "message"), + [ + (0.0, "rate_hz must be positive"), + (-1.0, "rate_hz must be positive"), + (float("nan"), "rate_hz must be finite"), + (float("inf"), "rate_hz must be finite"), + (float("-inf"), "rate_hz must be finite"), + ], +) +def test_to_grid_requires_a_finite_positive_rate(rate_hz: float, message: str) -> None: + with pytest.raises(ValueError, match=message): + to_grid(ramp_channel(), rate_hz, policy="interpolate") def test_derived_series_validates_column_lengths() -> None: