hdx-python-country 3.7.9__tar.gz → 3.8.1__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.7.9 → hdx_python_country-3.8.1}/PKG-INFO +1 -1
  2. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/documentation/main.md +4 -0
  3. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/requirements.txt +4 -4
  4. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/src/hdx/location/_version.py +2 -2
  5. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/src/hdx/location/adminlevel.py +34 -15
  6. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/tests/hdx/location/test_adminlevel.py +2 -2
  7. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/.config/coveragerc +0 -0
  8. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/.config/pre-commit-config.yaml +0 -0
  9. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/.config/pytest.ini +0 -0
  10. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/.config/ruff.toml +0 -0
  11. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/.github/workflows/publish.yaml +0 -0
  12. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/.github/workflows/run-python-tests.yaml +0 -0
  13. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/.gitignore +0 -0
  14. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/CONTRIBUTING.md +0 -0
  15. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/LICENSE +0 -0
  16. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/README.md +0 -0
  17. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/documentation/.readthedocs.yaml +0 -0
  18. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/documentation/pydoc-markdown.yaml +0 -0
  19. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/pyproject.toml +0 -0
  20. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/src/hdx/location/Countries & Territories Taxonomy MVP - C&T Taxonomy with HXL Tags.csv +0 -0
  21. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/src/hdx/location/__init__.py +0 -0
  22. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/src/hdx/location/country.py +0 -0
  23. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/src/hdx/location/currency.py +0 -0
  24. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/src/hdx/location/phonetics.py +0 -0
  25. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/src/hdx/location/wfp_exchangerates.py +0 -0
  26. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/tests/fixtures/adminlevel.yaml +0 -0
  27. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/tests/fixtures/adminlevelparent.yaml +0 -0
  28. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/tests/fixtures/download-global-pcode-lengths.csv +0 -0
  29. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/tests/fixtures/download-global-pcodes-adm-1-2.csv +0 -0
  30. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/tests/fixtures/secondary_historic_rates.csv +0 -0
  31. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/tests/fixtures/secondary_rates.json +0 -0
  32. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/tests/hdx/location/Countries_UZB_Deleted.csv +0 -0
  33. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/tests/hdx/location/__init__.py +0 -0
  34. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/tests/hdx/location/test_country.py +0 -0
  35. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/tests/hdx/location/test_currency.py +0 -0
  36. {hdx_python_country-3.7.9 → hdx_python_country-3.8.1}/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.7.9
3
+ Version: 3.8.1
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
@@ -130,6 +130,10 @@ object has been set up with parents). Keys take the form "STRING_TO_REPLACE",
130
130
  *admin_fuzzy_dont* is a list of names for which fuzzy matching should not be
131
131
  tried
132
132
 
133
+ A Retrieve object can be passed in the *retriever* parameter that enables
134
+ saving data downloaded to a file or loading previously saved data depending
135
+ on how the Retrieve object is configured.
136
+
133
137
  Once an AdminLevel object is constructed, one of three setup methods must be
134
138
  called: *setup_from_admin_info*, *setup_from_libhxl_dataset* or
135
139
  *setup_from_url*.
@@ -30,7 +30,7 @@ frictionless==5.18.0
30
30
  # via hdx-python-utilities
31
31
  hdx-python-utilities==3.7.4
32
32
  # via hdx-python-country (pyproject.toml)
33
- humanize==4.10.0
33
+ humanize==4.11.0
34
34
  # via frictionless
35
35
  identify==2.6.1
36
36
  # via pre-commit
@@ -82,7 +82,7 @@ ply==3.11
82
82
  # via
83
83
  # jsonpath-ng
84
84
  # libhxl
85
- pre-commit==3.8.0
85
+ pre-commit==4.0.0
86
86
  # via hdx-python-country (pyproject.toml)
87
87
  pydantic==2.9.2
88
88
  # via frictionless
@@ -127,7 +127,7 @@ requests-file==2.1.0
127
127
  # via hdx-python-utilities
128
128
  rfc3986==2.0.0
129
129
  # via frictionless
130
- rich==13.9.1
130
+ rich==13.9.2
131
131
  # via typer
132
132
  rpds-py==0.20.0
133
133
  # via
@@ -139,7 +139,7 @@ ruamel-yaml-clib==0.2.8
139
139
  # via ruamel-yaml
140
140
  shellingham==1.5.4
141
141
  # via typer
142
- simpleeval==0.9.13
142
+ simpleeval==1.0.0
143
143
  # via frictionless
144
144
  six==1.16.0
145
145
  # via
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '3.7.9'
16
- __version_tuple__ = version_tuple = (3, 7, 9)
15
+ __version__ = version = '3.8.1'
16
+ __version_tuple__ = version_tuple = (3, 8, 1)
@@ -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,22 +114,26 @@ 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
- def get_libhxl_dataset(self, url: str = _admin_url) -> hxl.Dataset:
119
+ @staticmethod
120
+ def get_libhxl_dataset(
121
+ url: str = admin_url, retriever: Optional[Retrieve] = None
122
+ ) -> hxl.Dataset:
119
123
  """
120
124
  Get libhxl Dataset object given a URL which defaults to global p-codes
121
125
  dataset on HDX.
122
126
 
123
127
  Args:
124
- admin_url (str): URL from which to load data.
128
+ url (str): URL from which to load data. Defaults to internal admin url.
129
+ retriever (Optional[Retrieve]): Retriever object to use for loading file. Defaults to None.
125
130
 
126
131
  Returns:
127
- None
132
+ hxl.Dataset: HXL Dataset object
128
133
  """
129
- if self.retriever:
134
+ if retriever:
130
135
  try:
131
- url_to_use = self.retriever.download_file(url)
136
+ url_to_use = retriever.download_file(url)
132
137
  except DownloadError:
133
138
  logger.exception(
134
139
  f"Setup of libhxl Dataset object with {url} failed!"
@@ -258,7 +263,7 @@ class AdminLevel:
258
263
 
259
264
  def setup_from_url(
260
265
  self,
261
- admin_url: str = _admin_url,
266
+ admin_url: str = admin_url,
262
267
  countryiso3s: Optional[ListTuple[str]] = None,
263
268
  ) -> None:
264
269
  """
@@ -271,21 +276,22 @@ class AdminLevel:
271
276
  Returns:
272
277
  None
273
278
  """
274
- admin_info = self.get_libhxl_dataset(admin_url)
279
+ admin_info = self.get_libhxl_dataset(admin_url, self.retriever)
275
280
  self.setup_from_libhxl_dataset(admin_info, countryiso3s)
276
281
 
277
- 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:
278
285
  """
279
- 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.
280
287
 
281
288
  Args:
282
- 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
283
290
 
284
291
  Returns:
285
292
  None
286
293
  """
287
- formats_info = self.get_libhxl_dataset(formats_url)
288
- for row in formats_info:
294
+ for row in libhxl_dataset:
289
295
  pcode_format = [int(row.get("#country+len"))]
290
296
  for admin_no in range(1, 4):
291
297
  length = row.get(f"#adm{admin_no}+len")
@@ -299,6 +305,19 @@ class AdminLevel:
299
305
  for x in re.finditer("0", pcode):
300
306
  dict_of_sets_add(self.zeroes, countryiso3, x.start())
301
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
+
302
321
  def set_parent_admins(self, parent_admins: List[List]) -> None:
303
322
  """
304
323
  Set parent admins
@@ -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