Skip to content

Commit

Permalink
fix: change pbf extract geometry propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
RaczeQ committed May 16, 2024
1 parent 78caa4e commit 4e7faf8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
5 changes: 2 additions & 3 deletions quackosm/pbf_file_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,17 +282,16 @@ def convert_pbf_to_parquet(
else:
pbf_path = list(pbf_path)

pbf_extract_geometry = None
if pbf_extract_geometry is not None:
if not isinstance(pbf_extract_geometry, BaseGeometry):
if isinstance(pbf_extract_geometry, BaseGeometry):
pbf_extract_geometry = [pbf_extract_geometry]

Check warning on line 287 in quackosm/pbf_file_reader.py

View check run for this annotation

Codecov / codecov/patch

quackosm/pbf_file_reader.py#L287

Added line #L287 was not covered by tests
else:
pbf_extract_geometry = list(pbf_extract_geometry)
if len(pbf_extract_geometry) != len(pbf_path):
raise AttributeError(

Check warning on line 291 in quackosm/pbf_file_reader.py

View check run for this annotation

Codecov / codecov/patch

quackosm/pbf_file_reader.py#L291

Added line #L291 was not covered by tests
"Provided pbf_extract_geometry has a different length "
"than the list of pbf paths."
)
pbf_extract_geometry = list(pbf_extract_geometry)

if filter_osm_ids is None:
filter_osm_ids = []
Expand Down
25 changes: 25 additions & 0 deletions tests/base/test_pbf_file_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import warnings
from functools import partial
from itertools import permutations
from pathlib import Path
from typing import Any, Callable, Optional, Union, cast
from unittest import TestCase
Expand Down Expand Up @@ -117,6 +118,30 @@ def test_geometry_hash_calculation(geometry: BaseGeometry):
== PbfFileReader(geometry_filter=oriented_b)._get_oriented_geometry_filter()
)

assert (
PbfFileReader(geometry_filter=oriented_a)._generate_geometry_hash()
== PbfFileReader(geometry_filter=oriented_b)._generate_geometry_hash()
)


def test_multipart_geometry_hash_calculation() -> None:
"""Test if geometry hash is orientation-agnostic."""
geom_1 = geometry_box()
geom_2 = box(minx=0, miny=0, maxx=1, maxy=1)
geom_3 = GeocodeGeometryParser().convert("Monaco-Ville, Monaco") # type: ignore
geom_4 = H3GeometryParser().convert("8a3969a40ac7fff,893969a4037ffff") # type: ignore

geoms = []

Check failure on line 134 in tests/base/test_pbf_file_reader.py

View workflow job for this annotation

GitHub Actions / Run pre-commit manual stage

Refurb FURB138

Consider using list comprehension
for combination in permutations([geom_1, geom_2, geom_3, geom_4], 4):
geoms.append(GeometryCollection(combination))

hashes = [
PbfFileReader(geometry_filter=geom_filter)._generate_geometry_hash()
for geom_filter in geoms
]

assert all(i == hashes[0] for i in hashes)


def test_unique_osm_ids_duplicated_file(): # type: ignore
"""Test if function returns results without duplicated features."""
Expand Down

0 comments on commit 4e7faf8

Please sign in to comment.