hestia-earth-utils 0.16.3__tar.gz → 0.16.5__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.
- {hestia_earth_utils-0.16.3/hestia_earth_utils.egg-info → hestia_earth_utils-0.16.5}/PKG-INFO +1 -1
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/csv_utils.py +38 -26
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/lookup.py +0 -3
- hestia_earth_utils-0.16.5/hestia_earth/utils/version.py +1 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5/hestia_earth_utils.egg-info}/PKG-INFO +1 -1
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/tests/test_lookup.py +7 -0
- hestia_earth_utils-0.16.3/hestia_earth/utils/version.py +0 -1
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/MANIFEST.in +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/README.md +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/bin/hestia-format-upload +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/bin/hestia-pivot-csv +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/__init__.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/api.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/blank_node.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/calculation_status.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/cycle.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/date.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/descriptive_stats.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/emission.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/lookup_utils.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/model.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/pipeline.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/pivot/__init__.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/pivot/_shared.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/pivot/pivot_csv.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/pivot/pivot_json.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/request.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/stats.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/storage/__init__.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/storage/_azure_client.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/storage/_local_client.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/storage/_s3_client.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/storage/_sns_client.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/table.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/term.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/tools.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth_utils.egg-info/SOURCES.txt +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth_utils.egg-info/dependency_links.txt +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth_utils.egg-info/requires.txt +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth_utils.egg-info/top_level.txt +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/setup.cfg +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/setup.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/tests/test_api.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/tests/test_blank_node.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/tests/test_calculation_status.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/tests/test_cycle.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/tests/test_date.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/tests/test_descriptive_stats.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/tests/test_emission.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/tests/test_lookup_utils.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/tests/test_model.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/tests/test_pipeline.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/tests/test_request.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/tests/test_stats.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/tests/test_table.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/tests/test_term.py +0 -0
- {hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/tests/test_tools.py +0 -0
|
@@ -25,16 +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
|
-
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
|
-
try:
|
|
33
|
-
return _replace_missing_values(next(reader)[0].strip())
|
|
34
|
-
except StopIteration:
|
|
35
|
-
return str(_MISSING)
|
|
36
|
-
|
|
37
|
-
|
|
38
28
|
def _get_columns(csv_content: str):
|
|
39
29
|
try:
|
|
40
30
|
reader = _text_to_csv(csv_content)
|
|
@@ -44,26 +34,48 @@ def _get_columns(csv_content: str):
|
|
|
44
34
|
return []
|
|
45
35
|
|
|
46
36
|
|
|
47
|
-
def
|
|
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):
|
|
48
48
|
names = _get_columns(csv_content)
|
|
49
49
|
num_cols = len(names)
|
|
50
50
|
|
|
51
|
-
converters_dict = {
|
|
52
|
-
i: _csv_reader_converter
|
|
53
|
-
for i in range(num_cols)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
# TODO: find the maximum column size instead of using 1000
|
|
57
51
|
max_size = 1000
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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)
|
|
67
79
|
|
|
68
80
|
|
|
69
81
|
def csv_file_to_recarray(filepath: str):
|
|
@@ -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
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
VERSION = '0.16.5'
|
|
@@ -154,3 +154,10 @@ def test_get_data_advanced():
|
|
|
154
154
|
lookup = download_lookup('liveAnimal.csv')
|
|
155
155
|
value = get_table_value(lookup, 'termid', 'sheepRam', column_name('ratioCPregnancyNetEnergyPregnancyIpcc2019'))
|
|
156
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.3'
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/calculation_status.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/descriptive_stats.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/pivot/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/pivot/pivot_csv.py
RENAMED
|
File without changes
|
{hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/pivot/pivot_json.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/storage/__init__.py
RENAMED
|
File without changes
|
{hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/storage/_azure_client.py
RENAMED
|
File without changes
|
{hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/storage/_local_client.py
RENAMED
|
File without changes
|
{hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/storage/_s3_client.py
RENAMED
|
File without changes
|
{hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth/utils/storage/_sns_client.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth_utils.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth_utils.egg-info/requires.txt
RENAMED
|
File without changes
|
{hestia_earth_utils-0.16.3 → hestia_earth_utils-0.16.5}/hestia_earth_utils.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|