Skip to content

Commit

Permalink
Time values must be increasing in check_values() + add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Stoops committed Dec 16, 2024
1 parent c3630d1 commit 3a25291
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ dependencies = [
"w3lib",
"typing-extensions>=4.12.0",
"StrEnum>=0.4.0",
"numpy",
]
dynamic = ["version"]

Expand All @@ -103,7 +104,6 @@ dev = [
"tox",
"build",
"ruff",
"numpy",
]

[project.urls]
Expand Down
3 changes: 3 additions & 0 deletions src/czml3/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
from typing import Any

import numpy as np
from dateutil.parser import isoparse as parse_iso_date
from pydantic import (
Field,
Expand Down Expand Up @@ -81,6 +82,8 @@ def check_values(num_points: int, values: list[Any]):
raise TypeError(
f"Input values must have either {num_points} or N * {num_points + 1} values, where N is the number of time-tagged samples."
)
if len(values) % (num_points + 1) == 0 and np.any(np.diff(values[::4]) <= 0):
raise TypeError("Time values must be increasing.")


def check_reference(r):
Expand Down
5 changes: 5 additions & 0 deletions tests/test_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -1648,3 +1648,8 @@ def test_position_list_of_lists_with_bad_references():
values=[["1#this"], ["1#this", "2#this"]]
),
)


def test_check_increasing_time():
with pytest.raises(TypeError):
Cartesian3Value(values=[0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0])

0 comments on commit 3a25291

Please sign in to comment.