From 1a76208721c14970ed2a4d755c61e6f0437f21b9 Mon Sep 17 00:00:00 2001 From: Paul van Schayck Date: Mon, 26 Feb 2024 10:12:52 +0100 Subject: [PATCH] Axis can be number (float or int) or str. CompactAis can be number (float or int). --- src/covjson_pydantic/domain.py | 10 +++++----- tests/test_coverage.py | 2 ++ tests/test_data/int-axes.json | 19 +++++++++++++++++++ tests/test_data/str-axes.json | 8 ++++++++ 4 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 tests/test_data/int-axes.json create mode 100644 tests/test_data/str-axes.json diff --git a/src/covjson_pydantic/domain.py b/src/covjson_pydantic/domain.py index 61dfdfb..02fbc20 100644 --- a/src/covjson_pydantic/domain.py +++ b/src/covjson_pydantic/domain.py @@ -17,8 +17,8 @@ class CompactAxis(CovJsonBaseModel): - start: float - stop: float + start: Union[int, float] + stop: Union[int, float] num: PositiveInt @model_validator(mode="after") @@ -56,9 +56,9 @@ class DomainType(str, Enum): class Axes(CovJsonBaseModel): - x: Optional[Union[ValuesAxis[float], CompactAxis]] = None - y: Optional[Union[ValuesAxis[float], CompactAxis]] = None - z: Optional[Union[ValuesAxis[float], CompactAxis]] = None + x: Optional[Union[ValuesAxis[float], ValuesAxis[int], ValuesAxis[str], CompactAxis]] = None + y: Optional[Union[ValuesAxis[float], ValuesAxis[int], ValuesAxis[str], CompactAxis]] = None + z: Optional[Union[ValuesAxis[float], ValuesAxis[int], ValuesAxis[str], CompactAxis]] = None t: Optional[ValuesAxis[AwareDatetime]] = None composite: Optional[ValuesAxis[Tuple]] = None diff --git a/tests/test_coverage.py b/tests/test_coverage.py index e21ad75..224bd9a 100644 --- a/tests/test_coverage.py +++ b/tests/test_coverage.py @@ -16,6 +16,8 @@ happy_cases = [ ("spec-axes.json", Axes), + ("int-axes.json", Axes), + ("str-axes.json", Axes), ("coverage-json.json", Coverage), ("doc-example-coverage.json", Coverage), ("spec-vertical-profile-coverage.json", Coverage), diff --git a/tests/test_data/int-axes.json b/tests/test_data/int-axes.json new file mode 100644 index 0000000..7e1c4c2 --- /dev/null +++ b/tests/test_data/int-axes.json @@ -0,0 +1,19 @@ +{ + "x": { + "values": [ + 20, + 21 + ], + "bounds": [ + 19, + 20, + 20, + 21 + ] + }, + "y": { + "start": 0, + "stop": 5, + "num": 6 + } +} diff --git a/tests/test_data/str-axes.json b/tests/test_data/str-axes.json new file mode 100644 index 0000000..157f673 --- /dev/null +++ b/tests/test_data/str-axes.json @@ -0,0 +1,8 @@ +{ + "x": { + "values": [ + "1", + "2" + ] + } +}