Skip to content

Commit

Permalink
refactor: Need to import PerformanceWarning to test module
Browse files Browse the repository at this point in the history
  • Loading branch information
r-leyshon committed Jun 19, 2024
1 parent 0d37238 commit ed563fe
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/transport_performance/osm/validate_osm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* Find coordinates for node or way features
* Plot the coordinates of a given list of node or way IDs
"""
import os
import warnings
from pathlib import Path
from typing import Union

Expand All @@ -37,6 +39,12 @@
# ---------utilities-----------


class PerformanceWarning(UserWarning):
"""Operation may be slow."""

pass


def _compile_tags(osmium_feature):
"""Return tag name value pairs.
Expand Down Expand Up @@ -553,6 +561,16 @@ def __init__(
_is_expected_filetype(
osm_pth, "osm_pth", check_existing=True, exp_ext=".pbf"
)
self.large_file_thresh = 50000 # 50 KB
# implement performance warning on large OSM files.
osm_size = os.path.getsize(osm_pth)
if osm_size > self.large_file_thresh:
warnings.warn(
f"PBF file is {osm_size} bytes. Tag operations are expensive."
" Consider filtering the pbf file smaller than"
f" {self.large_file_thresh} bytes",
PerformanceWarning,
)
tags = tag_collator()
classnm = tags.__class__.__name__
if classnm != "_TagHandler":
Expand Down

0 comments on commit ed563fe

Please sign in to comment.