hestia-earth-utils 0.16.4__tar.gz → 0.16.6__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.4/hestia_earth_utils.egg-info → hestia_earth_utils-0.16.6}/PKG-INFO +1 -1
  2. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth/utils/csv_utils.py +38 -24
  3. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth/utils/lookup.py +2 -1
  4. hestia_earth_utils-0.16.6/hestia_earth/utils/version.py +1 -0
  5. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6/hestia_earth_utils.egg-info}/PKG-INFO +1 -1
  6. hestia_earth_utils-0.16.4/hestia_earth/utils/version.py +0 -1
  7. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/MANIFEST.in +0 -0
  8. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/README.md +0 -0
  9. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/bin/hestia-format-upload +0 -0
  10. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/bin/hestia-pivot-csv +0 -0
  11. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth/utils/__init__.py +0 -0
  12. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth/utils/api.py +0 -0
  13. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth/utils/blank_node.py +0 -0
  14. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth/utils/calculation_status.py +0 -0
  15. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth/utils/cycle.py +0 -0
  16. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth/utils/date.py +0 -0
  17. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth/utils/descriptive_stats.py +0 -0
  18. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth/utils/emission.py +0 -0
  19. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth/utils/lookup_utils.py +0 -0
  20. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth/utils/model.py +0 -0
  21. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth/utils/pipeline.py +0 -0
  22. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth/utils/pivot/__init__.py +0 -0
  23. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth/utils/pivot/_shared.py +0 -0
  24. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth/utils/pivot/pivot_csv.py +0 -0
  25. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth/utils/pivot/pivot_json.py +0 -0
  26. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth/utils/request.py +0 -0
  27. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth/utils/stats.py +0 -0
  28. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth/utils/storage/__init__.py +0 -0
  29. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth/utils/storage/_azure_client.py +0 -0
  30. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth/utils/storage/_local_client.py +0 -0
  31. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth/utils/storage/_s3_client.py +0 -0
  32. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth/utils/storage/_sns_client.py +0 -0
  33. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth/utils/table.py +0 -0
  34. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth/utils/term.py +0 -0
  35. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth/utils/tools.py +0 -0
  36. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth_utils.egg-info/SOURCES.txt +0 -0
  37. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth_utils.egg-info/dependency_links.txt +0 -0
  38. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth_utils.egg-info/requires.txt +0 -0
  39. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/hestia_earth_utils.egg-info/top_level.txt +0 -0
  40. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/setup.cfg +0 -0
  41. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/setup.py +0 -0
  42. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/tests/test_api.py +0 -0
  43. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/tests/test_blank_node.py +0 -0
  44. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/tests/test_calculation_status.py +0 -0
  45. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/tests/test_cycle.py +0 -0
  46. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/tests/test_date.py +0 -0
  47. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/tests/test_descriptive_stats.py +0 -0
  48. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/tests/test_emission.py +0 -0
  49. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/tests/test_lookup.py +0 -0
  50. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/tests/test_lookup_utils.py +0 -0
  51. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/tests/test_model.py +0 -0
  52. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/tests/test_pipeline.py +0 -0
  53. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/tests/test_request.py +0 -0
  54. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/tests/test_stats.py +0 -0
  55. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/tests/test_table.py +0 -0
  56. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/tests/test_term.py +0 -0
  57. {hestia_earth_utils-0.16.4 → hestia_earth_utils-0.16.6}/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.4
3
+ Version: 0.16.6
4
4
  Summary: HESTIA's utils library
5
5
  Home-page: https://gitlab.com/hestia-earth/hestia-utils
6
6
  Author: HESTIA Team
@@ -25,14 +25,6 @@ def _text_to_csv(csv_content: str):
25
25
  return csv.reader(io.StringIO(csv_content.strip()), delimiter=_DELIMITER, quotechar=_QUOTE_CHAR)
26
26
 
27
27
 
28
- def _csv_reader_converter(field_str_bytes):
29
- try:
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:
33
- return str(_MISSING)
34
-
35
-
36
28
  def _get_columns(csv_content: str):
37
29
  try:
38
30
  reader = _text_to_csv(csv_content)
@@ -42,26 +34,48 @@ def _get_columns(csv_content: str):
42
34
  return []
43
35
 
44
36
 
45
- def csv_str_to_recarray(csv_content: str) -> np.recarray:
37
+ def _get_rows(csv_content: str):
38
+ string_io = io.StringIO(csv_content.strip())
39
+ try:
40
+ next(string_io)
41
+ except StopIteration:
42
+ return
43
+
44
+ return csv.reader(string_io, delimiter=_DELIMITER, quotechar=_QUOTE_CHAR)
45
+
46
+
47
+ def _csv_str_to_recarray_chunks_numpy(csv_content: str, chunk_size: int = 5):
46
48
  names = _get_columns(csv_content)
47
49
  num_cols = len(names)
48
50
 
49
- converters_dict = {
50
- i: _csv_reader_converter
51
- for i in range(num_cols)
52
- }
53
-
54
- # TODO: find the maximum column size instead of using 1000
55
51
  max_size = 1000
56
- return np.loadtxt(
57
- io.StringIO(csv_content.strip()),
58
- delimiter=_DELIMITER,
59
- quotechar=_QUOTE_CHAR,
60
- skiprows=1,
61
- converters=converters_dict,
62
- dtype=[(name, f"U{max_size}") for name in names],
63
- encoding=ENCODING
64
- ).view(np.recarray)
52
+ dtype = [(name, f"U{max_size}") for name in names]
53
+
54
+ reader = _get_rows(csv_content)
55
+
56
+ # 4. Process the file in batches
57
+ chunk_rows = []
58
+ for row in reader:
59
+ if not row:
60
+ continue
61
+ if len(row) != num_cols:
62
+ continue
63
+
64
+ # replace missing values
65
+ processed_row = tuple(_replace_missing_values(field) for field in row)
66
+ chunk_rows.append(processed_row)
67
+
68
+ if len(chunk_rows) >= chunk_size:
69
+ yield np.array(chunk_rows, dtype=dtype).view(np.recarray)
70
+ chunk_rows = []
71
+
72
+ if chunk_rows:
73
+ yield np.array(chunk_rows, dtype=dtype).view(np.recarray)
74
+
75
+
76
+ def csv_str_to_recarray(csv_content: str) -> np.recarray:
77
+ array_rows = list(_csv_str_to_recarray_chunks_numpy(csv_content))
78
+ return np.hstack(array_rows).view(np.recarray)
65
79
 
66
80
 
67
81
  def csv_file_to_recarray(filepath: str):
@@ -43,7 +43,8 @@ def _download_lookup_data(filename: str):
43
43
 
44
44
  def fallback():
45
45
  url = request_url(f"{web_url()}/{filepath}")
46
- return requests.get(url).content.decode('utf-8')
46
+ data = requests.get(url).content.decode('utf-8')
47
+ return data if data and '<html' not in data else None
47
48
 
48
49
  try:
49
50
  data = _load_from_storage(filepath, glossary=True)
@@ -0,0 +1 @@
1
+ VERSION = '0.16.6'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hestia_earth_utils
3
- Version: 0.16.4
3
+ Version: 0.16.6
4
4
  Summary: HESTIA's utils library
5
5
  Home-page: https://gitlab.com/hestia-earth/hestia-utils
6
6
  Author: HESTIA Team
@@ -1 +0,0 @@
1
- VERSION = '0.16.4'