Skip to content

Commit

Permalink
HDXDSYS-905 Fix for Blank adm name (#49)
Browse files Browse the repository at this point in the history
* Fix test before making changes

* Update fixture

* pcode lengths

* Add test to check that p-code with blank adm name can still be found

* Increase coverage

* Add log message for missing admin names
  • Loading branch information
mcarans authored Jul 22, 2024
1 parent 485f509 commit 4ae2760
Show file tree
Hide file tree
Showing 5 changed files with 2,126 additions and 3,926 deletions.
14 changes: 7 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ charset-normalizer==3.3.2
# via requests
click==8.1.7
# via typer
coverage==7.5.4
coverage==7.6.0
# via pytest-cov
distlib==0.3.8
# via virtualenv
Expand All @@ -30,7 +30,7 @@ frictionless==5.17.0
# via hdx-python-utilities
hdx-python-utilities==3.7.2
# via hdx-python-country (pyproject.toml)
humanize==4.9.0
humanize==4.10.0
# via frictionless
identify==2.6.0
# via pre-commit
Expand All @@ -48,7 +48,7 @@ jsonlines==4.0.0
# via hdx-python-utilities
jsonpath-ng==1.6.1
# via libhxl
jsonschema==4.22.0
jsonschema==4.23.0
# via
# frictionless
# tableschema-to-template
Expand Down Expand Up @@ -92,7 +92,7 @@ pygments==2.18.0
# via rich
pyphonetics==0.5.3
# via hdx-python-country (pyproject.toml)
pytest==8.2.2
pytest==8.3.1
# via
# hdx-python-country (pyproject.toml)
# pytest-cov
Expand Down Expand Up @@ -129,7 +129,7 @@ rfc3986==2.0.0
# via frictionless
rich==13.7.1
# via typer
rpds-py==0.18.1
rpds-py==0.19.0
# via
# jsonschema
# referencing
Expand All @@ -147,7 +147,7 @@ six==1.16.0
# python-dateutil
stringcase==1.2.0
# via frictionless
structlog==24.2.0
structlog==24.4.0
# via libhxl
tableschema-to-template==0.0.13
# via hdx-python-utilities
Expand All @@ -171,7 +171,7 @@ urllib3==2.2.2
# via
# libhxl
# requests
validators==0.30.0
validators==0.33.0
# via frictionless
virtualenv==20.26.3
# via pre-commit
Expand Down
14 changes: 10 additions & 4 deletions src/hdx/location/adminlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def setup_row(
self,
countryiso3: str,
pcode: str,
adm_name: str,
adm_name: Optional[str],
parent: Optional[str],
):
"""
Expand All @@ -134,22 +134,28 @@ def setup_row(
Args:
countryiso3 (str): Country
pcode (str): P-code
adm_name (str): Administrative name
adm_name (Optional[str]): Administrative name (which can be None)
parent (Optional[str]): Parent p-code
Returns:
None
"""
self.pcode_lengths[countryiso3] = len(pcode)
self.pcodes.append(pcode)
if adm_name is None:
adm_name = ""
self.pcode_to_name[pcode] = adm_name
self.pcode_to_iso3[pcode] = countryiso3
if not adm_name:
logger.error(
f"Admin name is blank for pcode {pcode} of {countryiso3}!"
)
return

adm_name = normalise(adm_name)
name_to_pcode = self.name_to_pcode.get(countryiso3, {})
name_to_pcode[adm_name] = pcode
self.name_to_pcode[countryiso3] = name_to_pcode
self.pcode_to_iso3[pcode] = countryiso3
self.pcode_to_iso3[pcode] = countryiso3

if self.use_parent:
name_parent_to_pcode = self.name_parent_to_pcode.get(
Expand Down
Loading

0 comments on commit 4ae2760

Please sign in to comment.