From 4e7faf8dba4412c44d3b367a102cb7d08eaf629d Mon Sep 17 00:00:00 2001 From: Kamil Raczycki Date: Thu, 16 May 2024 10:52:58 +0200 Subject: [PATCH] fix: change pbf extract geometry propagation --- quackosm/pbf_file_reader.py | 5 ++--- tests/base/test_pbf_file_reader.py | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/quackosm/pbf_file_reader.py b/quackosm/pbf_file_reader.py index 52097f5..dc822c2 100644 --- a/quackosm/pbf_file_reader.py +++ b/quackosm/pbf_file_reader.py @@ -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] else: + pbf_extract_geometry = list(pbf_extract_geometry) if len(pbf_extract_geometry) != len(pbf_path): raise AttributeError( "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 = [] diff --git a/tests/base/test_pbf_file_reader.py b/tests/base/test_pbf_file_reader.py index a03ca11..5c6e245 100644 --- a/tests/base/test_pbf_file_reader.py +++ b/tests/base/test_pbf_file_reader.py @@ -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 @@ -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 = [] + 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."""