hdx-python-country 3.8.0__tar.gz → 3.8.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/PKG-INFO +1 -1
  2. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/requirements.txt +9 -11
  3. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/src/hdx/location/_version.py +2 -2
  4. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/src/hdx/location/adminlevel.py +60 -11
  5. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/tests/fixtures/adminlevel.yaml +1 -1
  6. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/tests/hdx/location/test_adminlevel.py +3 -3
  7. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/.config/coveragerc +0 -0
  8. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/.config/pre-commit-config.yaml +0 -0
  9. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/.config/pytest.ini +0 -0
  10. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/.config/ruff.toml +0 -0
  11. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/.github/workflows/publish.yaml +0 -0
  12. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/.github/workflows/run-python-tests.yaml +0 -0
  13. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/.gitignore +0 -0
  14. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/CONTRIBUTING.md +0 -0
  15. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/LICENSE +0 -0
  16. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/README.md +0 -0
  17. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/documentation/.readthedocs.yaml +0 -0
  18. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/documentation/main.md +0 -0
  19. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/documentation/pydoc-markdown.yaml +0 -0
  20. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/pyproject.toml +0 -0
  21. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/src/hdx/location/Countries & Territories Taxonomy MVP - C&T Taxonomy with HXL Tags.csv +0 -0
  22. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/src/hdx/location/__init__.py +0 -0
  23. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/src/hdx/location/country.py +0 -0
  24. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/src/hdx/location/currency.py +0 -0
  25. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/src/hdx/location/phonetics.py +0 -0
  26. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/src/hdx/location/wfp_exchangerates.py +0 -0
  27. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/tests/fixtures/adminlevelparent.yaml +0 -0
  28. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/tests/fixtures/download-global-pcode-lengths.csv +0 -0
  29. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/tests/fixtures/download-global-pcodes-adm-1-2.csv +0 -0
  30. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/tests/fixtures/secondary_historic_rates.csv +0 -0
  31. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/tests/fixtures/secondary_rates.json +0 -0
  32. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/tests/hdx/location/Countries_UZB_Deleted.csv +0 -0
  33. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/tests/hdx/location/__init__.py +0 -0
  34. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/tests/hdx/location/test_country.py +0 -0
  35. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/tests/hdx/location/test_currency.py +0 -0
  36. {hdx_python_country-3.8.0 → hdx_python_country-3.8.2}/tests/hdx/location/test_wfp_exchangerates.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: hdx-python-country
3
- Version: 3.8.0
3
+ Version: 3.8.2
4
4
  Summary: HDX Python country code and exchange rate (fx) utilities
5
5
  Project-URL: Homepage, https://github.com/OCHA-DAP/hdx-python-country
6
6
  Author: Michael Rans
@@ -14,13 +14,13 @@ cfgv==3.4.0
14
14
  # via pre-commit
15
15
  chardet==5.2.0
16
16
  # via frictionless
17
- charset-normalizer==3.3.2
17
+ charset-normalizer==3.4.0
18
18
  # via requests
19
19
  click==8.1.7
20
20
  # via typer
21
- coverage==7.6.1
21
+ coverage==7.6.3
22
22
  # via pytest-cov
23
- distlib==0.3.8
23
+ distlib==0.3.9
24
24
  # via virtualenv
25
25
  et-xmlfile==1.1.0
26
26
  # via openpyxl
@@ -40,19 +40,19 @@ ijson==3.3.0
40
40
  # via hdx-python-utilities
41
41
  iniconfig==2.0.0
42
42
  # via pytest
43
- isodate==0.6.1
43
+ isodate==0.7.2
44
44
  # via frictionless
45
45
  jinja2==3.1.4
46
46
  # via frictionless
47
47
  jsonlines==4.0.0
48
48
  # via hdx-python-utilities
49
- jsonpath-ng==1.6.1
49
+ jsonpath-ng==1.7.0
50
50
  # via libhxl
51
51
  jsonschema==4.23.0
52
52
  # via
53
53
  # frictionless
54
54
  # tableschema-to-template
55
- jsonschema-specifications==2023.12.1
55
+ jsonschema-specifications==2024.10.1
56
56
  # via jsonschema
57
57
  libhxl==5.2.1
58
58
  # via hdx-python-country (pyproject.toml)
@@ -62,7 +62,7 @@ markdown-it-py==3.0.0
62
62
  # via rich
63
63
  marko==2.1.2
64
64
  # via frictionless
65
- markupsafe==2.1.5
65
+ markupsafe==3.0.1
66
66
  # via jinja2
67
67
  mdurl==0.1.2
68
68
  # via markdown-it-py
@@ -82,7 +82,7 @@ ply==3.11
82
82
  # via
83
83
  # jsonpath-ng
84
84
  # libhxl
85
- pre-commit==4.0.0
85
+ pre-commit==4.0.1
86
86
  # via hdx-python-country (pyproject.toml)
87
87
  pydantic==2.9.2
88
88
  # via frictionless
@@ -142,9 +142,7 @@ shellingham==1.5.4
142
142
  simpleeval==1.0.0
143
143
  # via frictionless
144
144
  six==1.16.0
145
- # via
146
- # isodate
147
- # python-dateutil
145
+ # via python-dateutil
148
146
  stringcase==1.2.0
149
147
  # via frictionless
150
148
  structlog==24.4.0
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '3.8.0'
16
- __version_tuple__ = version_tuple = (3, 8, 0)
15
+ __version__ = version = '3.8.2'
16
+ __version_tuple__ = version_tuple = (3, 8, 2)
@@ -50,9 +50,10 @@ class AdminLevel:
50
50
 
51
51
  pcode_regex = re.compile(r"^([a-zA-Z]{2,3})(\d+)$")
52
52
  _admin_url_default = "https://data.humdata.org/dataset/cb963915-d7d1-4ffa-90dc-31277e24406f/resource/f65bc260-4d8b-416f-ac07-f2433b4d5142/download/global_pcodes_adm_1_2.csv"
53
- _admin_url = _admin_url_default
53
+ admin_url = _admin_url_default
54
+ admin_all_pcodes_url = "https://data.humdata.org/dataset/cb963915-d7d1-4ffa-90dc-31277e24406f/resource/793e66fe-4cdb-4076-b037-fb8c053239e2/download/global_pcodes.csv"
54
55
  _formats_url_default = "https://data.humdata.org/dataset/cb963915-d7d1-4ffa-90dc-31277e24406f/resource/f1161807-dab4-4331-b7b0-4e5dac56e0e4/download/global_pcode_lengths.csv"
55
- _formats_url = _formats_url_default
56
+ formats_url = _formats_url_default
56
57
 
57
58
  def __init__(
58
59
  self,
@@ -113,11 +114,11 @@ class AdminLevel:
113
114
  """
114
115
  if admin_url is None:
115
116
  admin_url = cls._admin_url_default
116
- cls._admin_url = admin_url
117
+ cls.admin_url = admin_url
117
118
 
118
119
  @staticmethod
119
120
  def get_libhxl_dataset(
120
- url: str = _admin_url, retriever: Optional[Retrieve] = None
121
+ url: str = admin_url, retriever: Optional[Retrieve] = None
121
122
  ) -> hxl.Dataset:
122
123
  """
123
124
  Get libhxl Dataset object given a URL which defaults to global p-codes
@@ -262,7 +263,7 @@ class AdminLevel:
262
263
 
263
264
  def setup_from_url(
264
265
  self,
265
- admin_url: str = _admin_url,
266
+ admin_url: str = admin_url,
266
267
  countryiso3s: Optional[ListTuple[str]] = None,
267
268
  ) -> None:
268
269
  """
@@ -278,18 +279,19 @@ class AdminLevel:
278
279
  admin_info = self.get_libhxl_dataset(admin_url, self.retriever)
279
280
  self.setup_from_libhxl_dataset(admin_info, countryiso3s)
280
281
 
281
- def load_pcode_formats(self, formats_url: str = _formats_url) -> None:
282
+ def load_pcode_formats_from_libhxl_dataset(
283
+ self, libhxl_dataset: hxl.Dataset
284
+ ) -> None:
282
285
  """
283
- Load p-code formats from a URL. Defaults to global p-codes dataset on HDX.
286
+ Load p-code formats from a libhxl Dataset object.
284
287
 
285
288
  Args:
286
- formats_url (str): URL from which to load data. Defaults to global p-codes dataset.
289
+ libhxl_dataset (hxl.Dataset): Dataset object from libhxl library
287
290
 
288
291
  Returns:
289
292
  None
290
293
  """
291
- formats_info = self.get_libhxl_dataset(formats_url, self.retriever)
292
- for row in formats_info:
294
+ for row in libhxl_dataset:
293
295
  pcode_format = [int(row.get("#country+len"))]
294
296
  for admin_no in range(1, 4):
295
297
  length = row.get(f"#adm{admin_no}+len")
@@ -303,6 +305,19 @@ class AdminLevel:
303
305
  for x in re.finditer("0", pcode):
304
306
  dict_of_sets_add(self.zeroes, countryiso3, x.start())
305
307
 
308
+ def load_pcode_formats(self, formats_url: str = formats_url) -> None:
309
+ """
310
+ Load p-code formats from a URL. Defaults to global p-codes dataset on HDX.
311
+
312
+ Args:
313
+ formats_url (str): URL from which to load data. Defaults to global p-codes dataset.
314
+
315
+ Returns:
316
+ None
317
+ """
318
+ formats_info = self.get_libhxl_dataset(formats_url, self.retriever)
319
+ self.load_pcode_formats_from_libhxl_dataset(formats_info)
320
+
306
321
  def set_parent_admins(self, parent_admins: List[List]) -> None:
307
322
  """
308
323
  Set parent admins
@@ -587,6 +602,38 @@ class AdminLevel:
587
602
  continue
588
603
  return relevant_name_replacements
589
604
 
605
+ def get_admin_fuzzy_dont(
606
+ self, countryiso3: str, parent: Optional[str]
607
+ ) -> List[str]:
608
+ """Get relevant admin names that should not be fuzzy matched from
609
+ admin fuzzy dont which is a list of strings. These can be global
610
+ or they can be restricted by country or parent. Keys take the form
611
+ "DONT_MATCH", "AFG|DONT_MATCH", or "AF01|DONT_MATCH".
612
+
613
+ Args:
614
+ countryiso3 (str): ISO3 country code
615
+ parent (Optional[str]): Parent admin code
616
+
617
+ Returns:
618
+ List[str]: Relevant admin names that should not be fuzzy matched
619
+ """
620
+ relevant_admin_fuzzy_dont = []
621
+ for value in self.admin_fuzzy_dont:
622
+ if "|" not in value:
623
+ if value not in relevant_admin_fuzzy_dont:
624
+ relevant_admin_fuzzy_dont.append(value)
625
+ continue
626
+ prefix, name = value.split("|")
627
+ if parent:
628
+ if prefix == parent:
629
+ if name not in relevant_admin_fuzzy_dont:
630
+ relevant_admin_fuzzy_dont.append(name)
631
+ if prefix == countryiso3:
632
+ if name not in relevant_admin_fuzzy_dont:
633
+ relevant_admin_fuzzy_dont.append(name)
634
+ continue
635
+ return relevant_admin_fuzzy_dont
636
+
590
637
  def fuzzy_pcode(
591
638
  self,
592
639
  countryiso3: str,
@@ -643,7 +690,9 @@ class AdminLevel:
643
690
  pcode = name_to_pcode.get(
644
691
  normalised_name, name_to_pcode.get(alt_normalised_name)
645
692
  )
646
- if not pcode and name.lower() in self.admin_fuzzy_dont:
693
+ if not pcode and name.lower() in self.get_admin_fuzzy_dont(
694
+ countryiso3, parent
695
+ ):
647
696
  if logname:
648
697
  self.ignored.add((logname, countryiso3, name))
649
698
  return None
@@ -516,7 +516,7 @@ admin_name_replacements:
516
516
  " oblast": ""
517
517
 
518
518
  admin_fuzzy_dont:
519
- - "nord"
519
+ - "YEM|nord"
520
520
  - "north"
521
521
  - "sud"
522
522
  - "south"
@@ -381,9 +381,9 @@ class TestAdminLevel:
381
381
  adminone.setup_from_url("fake_url")
382
382
  adminone = AdminLevel(config)
383
383
  AdminLevel.set_default_admin_url()
384
- assert AdminLevel._admin_url == AdminLevel._admin_url_default
384
+ assert AdminLevel.admin_url == AdminLevel._admin_url_default
385
385
  AdminLevel.set_default_admin_url(url)
386
- assert AdminLevel._admin_url == url
386
+ assert AdminLevel.admin_url == url
387
387
  adminone.setup_from_url(countryiso3s=("YEM",))
388
388
  assert len(adminone.get_pcode_list()) == 22
389
389
 
@@ -421,7 +421,7 @@ class TestAdminLevel:
421
421
  adminone = AdminLevel(config)
422
422
  adminone.setup_from_url()
423
423
  assert adminone.get_admin_level("YEM") == 1
424
- assert len(adminone.get_pcode_list()) == 2510
424
+ assert len(adminone.get_pcode_list()) == 2526
425
425
  assert adminone.get_pcode_length("YEM") == 4
426
426
  assert adminone.get_pcode("YEM", "YE30", logname="test") == (
427
427
  "YE30",