Skip to content

Commit

Permalink
fix: allow filtering by geometry with silent verbosity mode
Browse files Browse the repository at this point in the history
  • Loading branch information
RaczeQ committed May 22, 2024
1 parent 1d7e0bf commit 3da466b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
10 changes: 5 additions & 5 deletions quackosm/_osm_tags_filters.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""Module contains a dedicated type alias for OSM tags filter."""

from collections.abc import Iterable
from collections.abc import Iterable, Mapping
from typing import Union, cast, overload

from quackosm._typing import is_expected_type

OsmTagsFilter = dict[str, Union[list[str], str, bool]]
OsmTagsFilter = Mapping[str, Union[list[str], str, bool]]

GroupedOsmTagsFilter = dict[str, OsmTagsFilter]
GroupedOsmTagsFilter = Mapping[str, OsmTagsFilter]


@overload
Expand Down Expand Up @@ -134,7 +134,7 @@ def _merge_multiple_osm_tags_filters(osm_tags_filters: Iterable[OsmTagsFilter])
"Provided filter doesn't match required `Iterable[OsmTagsFilter]` definition."
)

result: OsmTagsFilter = {}
result: dict[str, Union[list[str], str, bool]] = {}
for osm_tags_filter in osm_tags_filters:
for osm_tag_key, osm_tag_value in osm_tags_filter.items():
if osm_tag_key not in result:
Expand Down Expand Up @@ -175,4 +175,4 @@ def _merge_multiple_osm_tags_filters(osm_tags_filters: Iterable[OsmTagsFilter])
new_values = [value for value in osm_tag_value if value not in current_values_list]
current_values_list.extend(new_values)

return result
return cast(OsmTagsFilter, result)
6 changes: 4 additions & 2 deletions quackosm/_rich_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,12 @@ def __exit__(self, exc_type, exc_value, exc_tb):
self.progress = None

def create_manual_bar(self, total: int):
self.progress.add_task(description=self.step_name, total=total)
if self.progress:
self.progress.add_task(description=self.step_name, total=total)

def update_manual_bar(self, current_progress: int):
self.progress.update(task_id=self.progress.task_ids[0], completed=current_progress)
if self.progress:
self.progress.update(task_id=self.progress.task_ids[0], completed=current_progress)

def track(self, iterable: Iterable):
if self.progress is not None:
Expand Down
15 changes: 14 additions & 1 deletion tests/base/test_pbf_file_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from functools import partial
from itertools import permutations
from pathlib import Path
from typing import Any, Callable, Optional, Union, cast
from typing import Any, Callable, Literal, Optional, Union, cast
from unittest import TestCase

import duckdb
Expand Down Expand Up @@ -124,6 +124,19 @@ def test_geometry_hash_calculation(geometry: BaseGeometry):
)


@pytest.mark.parametrize("verbosity_mode", ["silent", "transient", "verbose"]) # type: ignore
def test_verbosity_mode(verbosity_mode: Literal["silent", "transient", "verbose"]) -> None:
"""Test if runs properly with different verbosity modes."""
pbf_file = Path(__file__).parent.parent / "test_files" / "monaco.osm.pbf"
convert_pbf_to_parquet(
pbf_file,
geometry_filter=GeocodeGeometryParser().convert("Monaco-Ville, Monaco"), # type: ignore
tags_filter={"amenity": True},
verbosity_mode=verbosity_mode,
ignore_cache=True,
)


def test_multipart_geometry_hash_calculation() -> None:
"""Test if geometry hash is orientation-agnostic."""
geom_1 = geometry_box()
Expand Down

0 comments on commit 3da466b

Please sign in to comment.