Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Allow integer values for crs parsing in Bounding Box #79

Merged
merged 1 commit into from
Jan 3, 2024
Merged
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
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 <lukas.weidenholzer@eodc.eu>", "Sean Hoyal <sean.hoyal@eodc.eu>", "Valentina Hutter <valentina.hutter@eodc.eu>", "Gerald Irsiegler <gerald.irsiegler@eodc.eu>"]
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