From 1a76208721c14970ed2a4d755c61e6f0437f21b9 Mon Sep 17 00:00:00 2001 From: Paul van Schayck Date: Mon, 26 Feb 2024 10:12:52 +0100 Subject: [PATCH 1/7] 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" + ] + } +} From fdcec4a7ede021591365dfcc99fb531e703a48e7 Mon Sep 17 00:00:00 2001 From: Paul van Schayck Date: Mon, 26 Feb 2024 10:17:51 +0100 Subject: [PATCH 2/7] Reverse order of int and float --- src/covjson_pydantic/domain.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/covjson_pydantic/domain.py b/src/covjson_pydantic/domain.py index 02fbc20..23930ad 100644 --- a/src/covjson_pydantic/domain.py +++ b/src/covjson_pydantic/domain.py @@ -56,9 +56,9 @@ class DomainType(str, Enum): class Axes(CovJsonBaseModel): - 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 + x: Optional[Union[ValuesAxis[int], ValuesAxis[float], ValuesAxis[str], CompactAxis]] = None + y: Optional[Union[ValuesAxis[int], ValuesAxis[float], ValuesAxis[str], CompactAxis]] = None + z: Optional[Union[ValuesAxis[int], ValuesAxis[float], ValuesAxis[str], CompactAxis]] = None t: Optional[ValuesAxis[AwareDatetime]] = None composite: Optional[ValuesAxis[Tuple]] = None From 9292b6c8968322ee64f3f6fdf6034d7bb82a79b2 Mon Sep 17 00:00:00 2001 From: Paul van Schayck Date: Tue, 5 Mar 2024 14:03:34 +0100 Subject: [PATCH 3/7] Add tests for mixed types in axes values --- tests/test_coverage.py | 1 + tests/test_data/mixed-type-axes.json | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 tests/test_data/mixed-type-axes.json diff --git a/tests/test_coverage.py b/tests/test_coverage.py index 224bd9a..c9ebc25 100644 --- a/tests/test_coverage.py +++ b/tests/test_coverage.py @@ -62,6 +62,7 @@ def test_happy_cases(file_name, object_type): + "domain must contain a single value.", ), ("point-series-domain-no-t.json", Domain, r"A 'PointSeries' must have a 't'-axis."), + ("mixed-type-axes.json", Axes, r"Input should be a valid number"), ] diff --git a/tests/test_data/mixed-type-axes.json b/tests/test_data/mixed-type-axes.json new file mode 100644 index 0000000..2546157 --- /dev/null +++ b/tests/test_data/mixed-type-axes.json @@ -0,0 +1,8 @@ +{ + "x": { + "values": [ + 42.0, + "foo" + ] + } +} From 6387a2f01f839ff9b81c5eff3a44c338eec13392 Mon Sep 17 00:00:00 2001 From: Paul van Schayck Date: Tue, 5 Mar 2024 14:12:26 +0100 Subject: [PATCH 4/7] Change strings test case to 'real' strings --- tests/test_data/str-axes.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_data/str-axes.json b/tests/test_data/str-axes.json index 157f673..525f7ce 100644 --- a/tests/test_data/str-axes.json +++ b/tests/test_data/str-axes.json @@ -1,8 +1,8 @@ { "x": { "values": [ - "1", - "2" + "foo", + "bar" ] } } From 8e5adc0f5bb06c88edbb65ba6e3eb104d75fcfcb Mon Sep 17 00:00:00 2001 From: Paul van Schayck Date: Fri, 29 Mar 2024 13:48:51 +0100 Subject: [PATCH 5/7] Remove ValuesAxis[int] --- src/covjson_pydantic/domain.py | 10 +++++----- tests/test_coverage.py | 1 - tests/test_data/int-axes.json | 19 ------------------- 3 files changed, 5 insertions(+), 25 deletions(-) delete mode 100644 tests/test_data/int-axes.json diff --git a/src/covjson_pydantic/domain.py b/src/covjson_pydantic/domain.py index 23930ad..af581c6 100644 --- a/src/covjson_pydantic/domain.py +++ b/src/covjson_pydantic/domain.py @@ -17,8 +17,8 @@ class CompactAxis(CovJsonBaseModel): - start: Union[int, float] - stop: Union[int, float] + start: float + stop: float num: PositiveInt @model_validator(mode="after") @@ -56,9 +56,9 @@ class DomainType(str, Enum): class Axes(CovJsonBaseModel): - x: Optional[Union[ValuesAxis[int], ValuesAxis[float], ValuesAxis[str], CompactAxis]] = None - y: Optional[Union[ValuesAxis[int], ValuesAxis[float], ValuesAxis[str], CompactAxis]] = None - z: Optional[Union[ValuesAxis[int], ValuesAxis[float], ValuesAxis[str], CompactAxis]] = None + x: Optional[Union[ValuesAxis[float], ValuesAxis[str], CompactAxis]] = None + y: Optional[Union[ValuesAxis[float], ValuesAxis[str], CompactAxis]] = None + z: Optional[Union[ValuesAxis[float], 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 c9ebc25..af23a45 100644 --- a/tests/test_coverage.py +++ b/tests/test_coverage.py @@ -16,7 +16,6 @@ happy_cases = [ ("spec-axes.json", Axes), - ("int-axes.json", Axes), ("str-axes.json", Axes), ("coverage-json.json", Coverage), ("doc-example-coverage.json", Coverage), diff --git a/tests/test_data/int-axes.json b/tests/test_data/int-axes.json deleted file mode 100644 index 7e1c4c2..0000000 --- a/tests/test_data/int-axes.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "x": { - "values": [ - 20, - 21 - ], - "bounds": [ - 19, - 20, - 20, - 21 - ] - }, - "y": { - "start": 0, - "stop": 5, - "num": 6 - } -} From a6d7cfbc43ccb9f77e3d67547a433a3a7e2cc560 Mon Sep 17 00:00:00 2001 From: Paul van Schayck Date: Tue, 2 Apr 2024 11:10:16 +0200 Subject: [PATCH 6/7] Add test for reverse order in a mixed type axis --- tests/test_coverage.py | 1 + tests/test_data/mixed-type-axes-2.json | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 tests/test_data/mixed-type-axes-2.json diff --git a/tests/test_coverage.py b/tests/test_coverage.py index af23a45..4c678e6 100644 --- a/tests/test_coverage.py +++ b/tests/test_coverage.py @@ -62,6 +62,7 @@ def test_happy_cases(file_name, object_type): ), ("point-series-domain-no-t.json", Domain, r"A 'PointSeries' must have a 't'-axis."), ("mixed-type-axes.json", Axes, r"Input should be a valid number"), + ("mixed-type-axes-2.json", Axes, r"Input should be a valid string"), ] diff --git a/tests/test_data/mixed-type-axes-2.json b/tests/test_data/mixed-type-axes-2.json new file mode 100644 index 0000000..538c6b9 --- /dev/null +++ b/tests/test_data/mixed-type-axes-2.json @@ -0,0 +1,8 @@ +{ + "x": { + "values": [ + "foo", + 42.0 + ] + } +} From dd6cd46235114416a116b013a728f38dbf30ae37 Mon Sep 17 00:00:00 2001 From: Paul van Schayck Date: Tue, 2 Apr 2024 11:10:28 +0200 Subject: [PATCH 7/7] Bump version to 0.3.0 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 725b130..30dde20 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,7 @@ classifiers = [ "Topic :: Scientific/Engineering :: GIS", "Typing :: Typed", ] -version = "0.2.1" +version = "0.3.0" dependencies = ["pydantic>=2.3,<3"] [project.optional-dependencies]