Skip to content

Commit

Permalink
173 filter invalid area names (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
i-be-snek authored Oct 31, 2024
1 parent ac1ba21 commit 703ec60
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions Database/scr/normalize_locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,20 @@ def normalize_locations(
try:
try:
if area:
assert isinstance(area, str), f"Area is not a string: {area}"
assert isinstance(area, str), f"Area `{area}` is not a string; type: {type(area)}"
if re.match(
"(country|location|area|adminarea|admin|admin_area|administrative area|administrative_area|none|null)(\s)*(s)*[0-9]*$",
area,
flags=re.IGNORECASE,
):
self.logger.error(f"Input `{area}` of type {type(area)} is not a valid area name")
return (None, None, None)
if in_country:
assert isinstance(in_country, str), f"Country is not a string: {in_country}"
assert not (
is_country and in_country
), f"An area cannot be a country (is_country={is_country}) and in a country (in_country={in_country}) simultaneously"

# if area is None, replace by country name
area = in_country if not area and in_country else area
assert isinstance(area, str), f"Area is {area}; in_country: {in_country}"

except BaseException as err:
self.logger.error(err)
return (None, None, None)
Expand Down

0 comments on commit 703ec60

Please sign in to comment.