hdx-python-utilities 4.2.1__py3-none-any.whl → 4.2.3__py3-none-any.whl

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.
hdx/utilities/_version.py CHANGED
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '4.2.1'
22
- __version_tuple__ = version_tuple = (4, 2, 1)
21
+ __version__ = version = '4.2.3'
22
+ __version_tuple__ = version_tuple = (4, 2, 3)
23
23
 
24
24
  __commit_id__ = commit_id = None
@@ -176,7 +176,7 @@ def get_frictionless_tableresource(
176
176
  if isinstance(headers[0], int):
177
177
  dialect.header_rows = headers
178
178
  else:
179
- detector.field_names = headers
179
+ detector.field_names = list(headers)
180
180
  if has_header is None:
181
181
  has_header = False
182
182
  if has_header is None:
hdx/utilities/matching.py CHANGED
@@ -2,7 +2,6 @@ import difflib
2
2
  import re
3
3
  from collections.abc import Callable, Sequence
4
4
 
5
- from pyphonetics import RefinedSoundex
6
5
  from rapidfuzz import fuzz as rapidfuzz_fuzz
7
6
 
8
7
  from hdx.utilities.text import normalise
@@ -57,64 +56,10 @@ def expand_initials(words: list[str], other_words: list[str]) -> list[str] | Non
57
56
  return expanded
58
57
 
59
58
 
60
- class Phonetics(RefinedSoundex):
61
- def match(
62
- self,
63
- possible_names: Sequence,
64
- name: str,
65
- alternative_name: str | None = None,
66
- transform_possible_names: Sequence[Callable] = [],
67
- threshold: int = 2,
68
- ) -> int | None:
69
- """
70
- Match name to one of the given possible names. Returns None if no match
71
- or the index of the matching name
72
-
73
- Args:
74
- possible_names: Possible names
75
- name: Name to match
76
- alternative_name: Alternative name to match. Defaults to None.
77
- transform_possible_names: Functions to transform possible names.
78
- threshold: Match threshold. Defaults to 2.
79
-
80
- Returns:
81
- Index of matching name from possible names or None
82
- """
83
- mindistance = None
84
- matching_index = None
85
-
86
- transform_possible_names.insert(0, lambda x: x)
87
-
88
- def check_name(name, possible_name):
89
- nonlocal mindistance, matching_index # noqa: E999
90
-
91
- distance = self.distance(name, possible_name)
92
- if mindistance is None or distance < mindistance:
93
- mindistance = distance
94
- matching_index = i
95
-
96
- for i, possible_name in enumerate(possible_names):
97
- for transform_possible_name in transform_possible_names:
98
- transformed_possible_name = transform_possible_name(possible_name)
99
- if not transformed_possible_name:
100
- continue
101
- check_name(name, transformed_possible_name)
102
- if alternative_name:
103
- check_name(alternative_name, transformed_possible_name)
104
- if mindistance is None or mindistance > threshold:
105
- return None
106
- return matching_index
107
-
108
-
109
59
  class RapidFuzzMatcher:
110
60
  """
111
- Default matcher for names, using rapidfuzz edit-distance scoring instead
112
- of phonetic (Soundex-family) encoding as Phonetics does. Phonetic algorithms
113
- encode English pronunciation rules, so they are a poor fit for matching
114
- multilingual or transliterated names (eg. "Sana'a" vs "Sanaa") that are
115
- spelling variants rather than being phonetically similar in English
116
- terms. Edit distance on normalised strings tends to place such variants
117
- closer together.
61
+ Matcher for names using rapidfuzz edit-distance scoring, which suits
62
+ multilingual or transliterated spelling variants (eg. "Sana'a" vs "Sanaa").
118
63
 
119
64
  Args:
120
65
  scorer: Function taking two strings and returning a similarity score
@@ -320,7 +265,6 @@ def get_code_from_name(
320
265
  unmatched: list[str],
321
266
  fuzzy_match: bool = True,
322
267
  match_threshold: int = 5,
323
- matcher: Phonetics | RapidFuzzMatcher | None = None,
324
268
  ) -> str | None:
325
269
  """
326
270
  Given a name (org type, sector, etc), return the corresponding code. A
@@ -333,7 +277,6 @@ def get_code_from_name(
333
277
  unmatched: List of unmatched names
334
278
  fuzzy_match: Allow fuzzy matching or not
335
279
  match_threshold: Match threshold
336
- matcher: Fuzzy matcher to use. Defaults to None (RapidFuzzMatcher).
337
280
 
338
281
  Returns:
339
282
  Matching code
@@ -359,9 +302,7 @@ def get_code_from_name(
359
302
  unmatched.append(name)
360
303
  return None
361
304
  names = [x for x in code_lookup.keys() if len(x) > match_threshold]
362
- if matcher is None:
363
- matcher = RapidFuzzMatcher()
364
- name_index = matcher.match(
305
+ name_index = RapidFuzzMatcher().match(
365
306
  possible_names=names,
366
307
  name=name,
367
308
  alternative_name=name_clean,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: hdx-python-utilities
3
- Version: 4.2.1
3
+ Version: 4.2.3
4
4
  Summary: HDX Python Utilities for streaming tabular data, date and time handling and other helpful functions
5
5
  Project-URL: Homepage, https://github.com/OCHA-DAP/hdx-python-utilities
6
6
  Author-email: Michael Rans <rans@email.com>
@@ -30,7 +30,6 @@ Requires-Dist: ijson>=3.5.0
30
30
  Requires-Dist: jsonlines>=4.0.0
31
31
  Requires-Dist: loguru
32
32
  Requires-Dist: openpyxl>=3.1.2
33
- Requires-Dist: pyphonetics
34
33
  Requires-Dist: python-dateutil<2.9.1,>=2.9.0
35
34
  Requires-Dist: rapidfuzz
36
35
  Requires-Dist: ratelimit
@@ -1,5 +1,5 @@
1
1
  hdx/utilities/__init__.py,sha256=DQztoBWScN4UoX3pTjA6JN_CHX-Lls3duu41YLJtdcM,72
2
- hdx/utilities/_version.py,sha256=kxocUPTpRazD_gOzTGXxjHRlGlmvTYAbC5HuA9k7iOc,520
2
+ hdx/utilities/_version.py,sha256=21amJoXCtnqCF82G0b3U092e2mAWEVhjbNYbWBX862A,520
3
3
  hdx/utilities/base_downloader.py,sha256=SzGSz57CwdmtvL2gaNAldXtfQ4uN4F5mjYkBAyq3U7M,3501
4
4
  hdx/utilities/compare.py,sha256=3w12iMELCBsR9gKXM7zyRZAf8YSeRylJwmGuLlEkAVQ,1145
5
5
  hdx/utilities/dateparse.py,sha256=Rlg6YM-Rt8jol-6vKy1OfLemnsx3DfRJj4dIfALUe_E,42170
@@ -11,10 +11,10 @@ hdx/utilities/encoding.py,sha256=_y7kdLG-AFkwIrbG-pNmsWQNbIv8GGNK8nFEpbnWSzI,210
11
11
  hdx/utilities/error_handler.py,sha256=bzT08uMzefn4XetUmONPSMV2zKjRDBGQ6adWdSMOc2U,5821
12
12
  hdx/utilities/errors_onexit.py,sha256=mnllrcWJt3zbfzAact-UWU-ZhymhWCZpPmMfpZCfVEU,383
13
13
  hdx/utilities/file_hashing.py,sha256=p9AN7m4OUFXbzgdtBUFw_npmD_T0l7oFmErjclZSX8k,3618
14
- hdx/utilities/frictionless_wrapper.py,sha256=ooDqT0FxlPa6iTBJkedm0NMRzLjt9plI_BnPPtZiu1c,8517
14
+ hdx/utilities/frictionless_wrapper.py,sha256=ZSv42AC07EN-RQ8jvo6lppLTQiF8H1354F5Ji0pJSVc,8523
15
15
  hdx/utilities/html.py,sha256=KX5m9mXbSsruzqIVg60REJMvvtd0R_pahrKUb4bGPYQ,2880
16
16
  hdx/utilities/loader.py,sha256=_0cbraMPneahCiQCetUovwMMaHCBmPhirys9QPMiD7c,6097
17
- hdx/utilities/matching.py,sha256=kpUpAnBVAwo9kBj25YK3yGQq8Cwq8-O-8HQv4GM8ky8,20599
17
+ hdx/utilities/matching.py,sha256=iBpPVhObqemqRsHOpNOImAKrVQvsd9aGarCvyasVXwk,18262
18
18
  hdx/utilities/path.py,sha256=CKyWY-iazfOKL2Nrwi9t8EvN5xMQKLd-yXxyE5wKLv8,15423
19
19
  hdx/utilities/retriever.py,sha256=kTrl_LneksM6C7FyWVfwd1-W7qUHnHrqr64lO8MLHuw,18386
20
20
  hdx/utilities/saver.py,sha256=O9QHGjqH9E4UMnDzmDPmvINCq8qGbljq4U_l9VnLfdM,8038
@@ -25,7 +25,7 @@ hdx/utilities/url.py,sha256=iN4tqU7sbpXc3EXMNaQfoot8Wm98AvDKN_oKS2heuAE,4312
25
25
  hdx/utilities/useragent.py,sha256=u1nwquIei93lLMAGqHrLs0w99qIIM1A2yUY7AOMSFy4,6862
26
26
  hdx/utilities/uuid.py,sha256=KUpQoo0P3RFO_n6-qdxTDxdaJMUpkTosdI0ulyk-RYA,557
27
27
  hdx/utilities/zip_crc.py,sha256=qs-81dd1oX6uIfwH7DUoZaS7OngHwOb7lnogBVmtBl8,4275
28
- hdx_python_utilities-4.2.1.dist-info/METADATA,sha256=EV3Tam6lFAmR7UcUYvR2i0Hk0R4txJJtVYGU49_fo6M,5522
29
- hdx_python_utilities-4.2.1.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
30
- hdx_python_utilities-4.2.1.dist-info/licenses/LICENSE,sha256=wc-4GpMn-ODs-U_bTe1YCiPVgvcjzrpYOx2wPuyAeII,1079
31
- hdx_python_utilities-4.2.1.dist-info/RECORD,,
28
+ hdx_python_utilities-4.2.3.dist-info/METADATA,sha256=3LCVLm7yts7CpVk_i7t_6Jg4lZJhn2haGg3Ry74CHIk,5495
29
+ hdx_python_utilities-4.2.3.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
30
+ hdx_python_utilities-4.2.3.dist-info/licenses/LICENSE,sha256=wc-4GpMn-ODs-U_bTe1YCiPVgvcjzrpYOx2wPuyAeII,1079
31
+ hdx_python_utilities-4.2.3.dist-info/RECORD,,