Skip to content

Commit

Permalink
Fix: Allow integer values for crs parsing in Bounding Box (#79)
Browse files Browse the repository at this point in the history
Co-authored-by: Gerald Walter Irsiegler <gerald@Irsiegler-P14s>
  • Loading branch information
GeraldIr and Gerald Walter Irsiegler authored Jan 3, 2024
1 parent 6dd6aed commit fd9fb55
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
6 changes: 3 additions & 3 deletions openeo_pg_parser_networkx/pg_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class PGEdgeType(str, Enum):


def parse_crs(v) -> pyproj.CRS:
if v is None or v.strip() == "":
if not isinstance(v, int) and (v is None or v.strip() == ""):
return DEFAULT_CRS
else:
try:
Expand All @@ -122,7 +122,7 @@ def parse_crs(v) -> pyproj.CRS:
raise e


def crs_validator(field: str) -> classmethod:
def crs_validator(field: Union[str, int]) -> classmethod:
decorator = validator(field, allow_reuse=True, pre=True, always=True)
validator_func = decorator(parse_crs)
return validator_func
Expand All @@ -135,7 +135,7 @@ class BoundingBox(BaseModel, arbitrary_types_allowed=True):
south: float
base: Optional[float]
height: Optional[float]
crs: Optional[str]
crs: Optional[Union[str, int]]

# validators
_parse_crs: classmethod = crs_validator('crs')
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "openeo-pg-parser-networkx"
version = "2023.11.0"
version = "2024.1.1"

description = "Parse OpenEO process graphs from JSON to traversible Python objects."
authors = ["Lukas Weidenholzer <[email protected]>", "Sean Hoyal <[email protected]>", "Valentina Hutter <[email protected]>", "Gerald Irsiegler <[email protected]>"]
Expand Down
22 changes: 21 additions & 1 deletion tests/test_pg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,15 @@ def test_bounding_box(get_process_graph_with_args):
assert parsed_arg.crs == pyproj.CRS.from_user_input('EPSG:2025').to_wkt()


def test_pydantic_loading():
test_extent = {'west': 0, 'east': 10, 'south': 0, 'north': 10}
test_bb = BoundingBox(**test_extent)
assert test_bb.crs == DEFAULT_CRS


def test_bounding_box_no_crs(get_process_graph_with_args):
pg = get_process_graph_with_args(
{'spatial_extent': {'west': 0, 'east': 10, 'south': 0, 'north': 10, 'crs': ""}}
{'spatial_extent': {'west': 0, 'east': 10, 'south': 0, 'north': 10}}
)
parsed_arg = (
ProcessGraph.parse_obj(pg)
Expand Down Expand Up @@ -153,6 +159,20 @@ def test_bounding_box_with_faulty_crs(get_process_graph_with_args):
]


def test_bounding_box_int_crs(get_process_graph_with_args):
pg = get_process_graph_with_args(
{'spatial_extent': {'west': 0, 'east': 10, 'south': 0, 'north': 10, 'crs': 4326}}
)
parsed_arg = (
ProcessGraph.parse_obj(pg)
.process_graph[TEST_NODE_KEY]
.arguments["spatial_extent"]
)
assert isinstance(parsed_arg, BoundingBox)
assert isinstance(parsed_arg.crs, str)
assert parsed_arg.crs == DEFAULT_CRS


@pytest.mark.skip(
reason="Not passing because of https://github.com/developmentseed/geojson-pydantic/issues/92"
)
Expand Down

0 comments on commit fd9fb55

Please sign in to comment.