Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/hflow/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 13 additions & 3 deletions tests/test_resample_derive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading