hestia-earth-utils 0.16.2__tar.gz → 0.16.4__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 (57) hide show
  1. {hestia_earth_utils-0.16.2/hestia_earth_utils.egg-info → hestia_earth_utils-0.16.4}/PKG-INFO +1 -1
  2. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth/utils/csv_utils.py +3 -5
  3. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth/utils/lookup.py +4 -5
  4. hestia_earth_utils-0.16.4/hestia_earth/utils/version.py +1 -0
  5. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4/hestia_earth_utils.egg-info}/PKG-INFO +1 -1
  6. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/tests/test_lookup.py +17 -4
  7. hestia_earth_utils-0.16.2/hestia_earth/utils/version.py +0 -1
  8. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/MANIFEST.in +0 -0
  9. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/README.md +0 -0
  10. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/bin/hestia-format-upload +0 -0
  11. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/bin/hestia-pivot-csv +0 -0
  12. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth/utils/__init__.py +0 -0
  13. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth/utils/api.py +0 -0
  14. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth/utils/blank_node.py +0 -0
  15. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth/utils/calculation_status.py +0 -0
  16. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth/utils/cycle.py +0 -0
  17. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth/utils/date.py +0 -0
  18. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth/utils/descriptive_stats.py +0 -0
  19. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth/utils/emission.py +0 -0
  20. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth/utils/lookup_utils.py +0 -0
  21. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth/utils/model.py +0 -0
  22. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth/utils/pipeline.py +0 -0
  23. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth/utils/pivot/__init__.py +0 -0
  24. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth/utils/pivot/_shared.py +0 -0
  25. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth/utils/pivot/pivot_csv.py +0 -0
  26. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth/utils/pivot/pivot_json.py +0 -0
  27. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth/utils/request.py +0 -0
  28. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth/utils/stats.py +0 -0
  29. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth/utils/storage/__init__.py +0 -0
  30. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth/utils/storage/_azure_client.py +0 -0
  31. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth/utils/storage/_local_client.py +0 -0
  32. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth/utils/storage/_s3_client.py +0 -0
  33. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth/utils/storage/_sns_client.py +0 -0
  34. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth/utils/table.py +0 -0
  35. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth/utils/term.py +0 -0
  36. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth/utils/tools.py +0 -0
  37. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth_utils.egg-info/SOURCES.txt +0 -0
  38. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth_utils.egg-info/dependency_links.txt +0 -0
  39. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth_utils.egg-info/requires.txt +0 -0
  40. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/hestia_earth_utils.egg-info/top_level.txt +0 -0
  41. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/setup.cfg +0 -0
  42. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/setup.py +0 -0
  43. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/tests/test_api.py +0 -0
  44. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/tests/test_blank_node.py +0 -0
  45. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/tests/test_calculation_status.py +0 -0
  46. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/tests/test_cycle.py +0 -0
  47. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/tests/test_date.py +0 -0
  48. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/tests/test_descriptive_stats.py +0 -0
  49. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/tests/test_emission.py +0 -0
  50. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/tests/test_lookup_utils.py +0 -0
  51. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/tests/test_model.py +0 -0
  52. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/tests/test_pipeline.py +0 -0
  53. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/tests/test_request.py +0 -0
  54. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/tests/test_stats.py +0 -0
  55. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/tests/test_table.py +0 -0
  56. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/tests/test_term.py +0 -0
  57. {hestia_earth_utils-0.16.2 → hestia_earth_utils-0.16.4}/tests/test_tools.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hestia_earth_utils
3
- Version: 0.16.2
3
+ Version: 0.16.4
4
4
  Summary: HESTIA's utils library
5
5
  Home-page: https://gitlab.com/hestia-earth/hestia-utils
6
6
  Author: HESTIA Team
@@ -26,12 +26,10 @@ def _text_to_csv(csv_content: str):
26
26
 
27
27
 
28
28
  def _csv_reader_converter(field_str_bytes):
29
- field_str = field_str_bytes if isinstance(field_str_bytes, str) else field_str_bytes.decode('utf-8')
30
- reader = _text_to_csv(field_str)
31
-
32
29
  try:
33
- return _replace_missing_values(next(reader)[0].strip())
34
- except StopIteration:
30
+ field_str = field_str_bytes if isinstance(field_str_bytes, str) else field_str_bytes.decode('utf-8')
31
+ return _replace_missing_values(field_str)
32
+ except Exception:
35
33
  return str(_MISSING)
36
34
 
37
35
 
@@ -2,7 +2,6 @@ from functools import reduce
2
2
  from typing import Union
3
3
  import requests
4
4
  import numpy
5
- import traceback
6
5
 
7
6
  from .storage import _load_from_storage
8
7
  from .request import request_url, web_url
@@ -92,8 +91,6 @@ def download_lookup(filename: str, keep_in_memory: bool = True, build_index: boo
92
91
  try:
93
92
  return _memory_wrapper(filename, load) if keep_in_memory else load()
94
93
  except Exception:
95
- stack = traceback.format_exc()
96
- print(stack)
97
94
  return None
98
95
 
99
96
 
@@ -142,7 +139,7 @@ def _get_multiple_table_values(data: Union[dict, numpy.recarray], col_match: str
142
139
  return reduce(reducer, enumerate(col_match), data)[col_val][0]
143
140
 
144
141
 
145
- def get_table_value(lookup: Union[dict, numpy.recarray], col_match: str, col_match_with, col_val):
142
+ def get_table_value(lookup: Union[dict, numpy.recarray], col_match: str, col_match_with, col_val, default_value=''):
146
143
  """
147
144
  Get a value matched by one or more columns from a `numpy.recarray`.
148
145
 
@@ -158,6 +155,8 @@ def get_table_value(lookup: Union[dict, numpy.recarray], col_match: str, col_mat
158
155
  Can be a single `str` or a list of `str`. If a list is used, must be the same length as `col_match`.
159
156
  col_val: str
160
157
  The column which contains the value to look for.
158
+ default_value : Any
159
+ A value to return when none if found in the data.
161
160
 
162
161
  Returns
163
162
  -------
@@ -170,7 +169,7 @@ def get_table_value(lookup: Union[dict, numpy.recarray], col_match: str, col_mat
170
169
  _get_single_table_value(lookup, col_match, col_match_with, col_val) if single else
171
170
  _get_multiple_table_values(lookup, col_match, col_match_with, col_val)
172
171
  )
173
- return None if is_missing_value(value) else _parse_value(value)
172
+ return default_value if is_missing_value(value) else _parse_value(value)
174
173
  except Exception:
175
174
  return None
176
175
 
@@ -0,0 +1 @@
1
+ VERSION = '0.16.4'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hestia_earth_utils
3
- Version: 0.16.2
3
+ Version: 0.16.4
4
4
  Summary: HESTIA's utils library
5
5
  Home-page: https://gitlab.com/hestia-earth/hestia-utils
6
6
  Author: HESTIA Team
@@ -56,11 +56,11 @@ def test_get_table_value():
56
56
 
57
57
  def test_get_table_value_empty():
58
58
  lookup = load_lookup(f"{fixtures_path}/lookup.csv")
59
- assert get_table_value(lookup, column_name('Col1'), 'val10', column_name('Col4')) is None
60
- assert get_table_value(lookup, column_name('Col2'), 'val22', column_name('Col1')) is None
59
+ assert get_table_value(lookup, column_name('Col1'), 'val10', column_name('Col4'), default_value=None) is None
60
+ assert get_table_value(lookup, column_name('Col2'), 'val22', column_name('Col1')) == ''
61
61
 
62
62
  lookup = download_lookup('crop.csv')
63
- assert get_table_value(lookup, 'termid', 'genericCropSeed', column_name('Plantation_density')) is None
63
+ assert get_table_value(lookup, 'termid', 'genericCropSeed', column_name('Plantation_density')) == ''
64
64
 
65
65
 
66
66
  def test_find_term_ids_by():
@@ -83,7 +83,7 @@ def test_download_lookup_without_index():
83
83
  def test_handle_missing_float_value():
84
84
  filename = 'measurement.csv'
85
85
  lookup = download_lookup(filename)
86
- assert get_table_value(lookup, 'termid', 'rainfallPeriod', 'maximum') is None
86
+ assert get_table_value(lookup, 'termid', 'rainfallPeriod', 'maximum') == ''
87
87
 
88
88
 
89
89
  def test_handle_missing_string_value():
@@ -148,3 +148,16 @@ def test_lookup_term_ids():
148
148
 
149
149
  def test_lookup_columns():
150
150
  assert 'termid' in lookup_columns(download_lookup('crop.csv'))
151
+
152
+
153
+ def test_get_data_advanced():
154
+ lookup = download_lookup('liveAnimal.csv')
155
+ value = get_table_value(lookup, 'termid', 'sheepRam', column_name('ratioCPregnancyNetEnergyPregnancyIpcc2019'))
156
+ assert value == ''
157
+
158
+
159
+ def test_grouping_with_comma():
160
+ lookup = download_lookup('animalProduct.csv')
161
+ term_id = 'meatChickenReadyToCookWeight'
162
+ value = get_table_value(lookup, 'termid', term_id, column_name('animalProductGroupingFAO'))
163
+ assert value == 'Meat of chickens, fresh or chilled'
@@ -1 +0,0 @@
1
- VERSION = '0.16.2'