hestia-earth-utils 0.15.2__py3-none-any.whl → 0.15.4__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.
- hestia_earth/utils/lookup.py +9 -4
- hestia_earth/utils/pipeline.py +1 -1
- hestia_earth/utils/term.py +31 -0
- hestia_earth/utils/version.py +1 -1
- {hestia_earth_utils-0.15.2.dist-info → hestia_earth_utils-0.15.4.dist-info}/METADATA +3 -2
- {hestia_earth_utils-0.15.2.dist-info → hestia_earth_utils-0.15.4.dist-info}/RECORD +10 -9
- {hestia_earth_utils-0.15.2.data → hestia_earth_utils-0.15.4.data}/scripts/hestia-format-upload +0 -0
- {hestia_earth_utils-0.15.2.data → hestia_earth_utils-0.15.4.data}/scripts/hestia-pivot-csv +0 -0
- {hestia_earth_utils-0.15.2.dist-info → hestia_earth_utils-0.15.4.dist-info}/WHEEL +0 -0
- {hestia_earth_utils-0.15.2.dist-info → hestia_earth_utils-0.15.4.dist-info}/top_level.txt +0 -0
hestia_earth/utils/lookup.py
CHANGED
|
@@ -90,10 +90,15 @@ def _download_lookup_data(filename: str):
|
|
|
90
90
|
|
|
91
91
|
def _build_index(array: numpy.recarray):
|
|
92
92
|
columns = list(array.dtype.names)
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
try:
|
|
94
|
+
return {
|
|
95
|
+
row[_INDEX_COL]: {col: row[col] for col in columns}
|
|
96
|
+
for row in array
|
|
97
|
+
} if _INDEX_COL in columns else array
|
|
98
|
+
except TypeError:
|
|
99
|
+
return {
|
|
100
|
+
array[_INDEX_COL].item(): {col: array[col].item() for col in columns}
|
|
101
|
+
} if _INDEX_COL in columns else array
|
|
97
102
|
|
|
98
103
|
|
|
99
104
|
def download_lookup(filename: str, keep_in_memory: bool = True, build_index: bool = False):
|
hestia_earth/utils/pipeline.py
CHANGED
|
@@ -25,7 +25,7 @@ class NpEncoder(json.JSONEncoder):
|
|
|
25
25
|
return super(NpEncoder, self).default(obj)
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
def to_string(data: dict): return json.dumps(data, ensure_ascii=False, cls=NpEncoder)
|
|
28
|
+
def to_string(data: dict, indent: int = None): return json.dumps(data, indent=indent, ensure_ascii=False, cls=NpEncoder)
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
def to_bytes(data: dict): return to_string(data).encode('utf8')
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from functools import lru_cache
|
|
3
|
+
from typing import Union
|
|
4
|
+
from hestia_earth.schema import TermTermType
|
|
5
|
+
|
|
6
|
+
from .storage import _load_from_storage
|
|
7
|
+
from .api import download_hestia
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@lru_cache()
|
|
11
|
+
def _load_term_file(term_type: str):
|
|
12
|
+
try:
|
|
13
|
+
filepath = f"glossary/{term_type}.json"
|
|
14
|
+
nodes = json.loads(_load_from_storage(filepath, glossary=True))
|
|
15
|
+
return {node.get('@id'): node for node in nodes}
|
|
16
|
+
except Exception:
|
|
17
|
+
return {}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def download_term(term: Union[str, dict], termType: Union[str, TermTermType] = None):
|
|
21
|
+
"""
|
|
22
|
+
Download a Term, using the glossary file if available, or default to the standard download.
|
|
23
|
+
"""
|
|
24
|
+
term_id = term.get('@id', term.get('id')) if isinstance(term, dict) else term
|
|
25
|
+
term_type = (
|
|
26
|
+
termType if isinstance(termType, str) else termType.value
|
|
27
|
+
) if termType else (
|
|
28
|
+
term.get('termType') if isinstance(term, dict) else None
|
|
29
|
+
)
|
|
30
|
+
cached_nodes = _load_term_file(term_type) if term_type else {}
|
|
31
|
+
return cached_nodes.get(term_id) or download_hestia(term_id)
|
hestia_earth/utils/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
VERSION = '0.15.
|
|
1
|
+
VERSION = '0.15.4'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: hestia-earth-utils
|
|
3
|
-
Version: 0.15.
|
|
3
|
+
Version: 0.15.4
|
|
4
4
|
Summary: HESTIA's utils library
|
|
5
5
|
Home-page: https://gitlab.com/hestia-earth/hestia-utils
|
|
6
6
|
Author: HESTIA Team
|
|
@@ -13,7 +13,8 @@ Requires-Python: >=3.9
|
|
|
13
13
|
Description-Content-Type: text/markdown
|
|
14
14
|
Requires-Dist: hestia-earth.schema>=24.3.0
|
|
15
15
|
Requires-Dist: requests>=2.24.0
|
|
16
|
-
Requires-Dist:
|
|
16
|
+
Requires-Dist: urllib3~=1.26.0
|
|
17
|
+
Requires-Dist: python-dateutil>=2.8.1
|
|
17
18
|
Requires-Dist: numpy<2,>=1.25.0
|
|
18
19
|
Requires-Dist: flatten-json
|
|
19
20
|
|
|
@@ -7,15 +7,16 @@ hestia_earth/utils/cycle.py,sha256=rFLRL9X4KQ1UrE6fEPA_gV8KmwzrZpR3Ce56zg41lRk,1
|
|
|
7
7
|
hestia_earth/utils/date.py,sha256=SPQ69uxHiv1o3BqIkBKkM5XX_CmS20CB7g6u2rhsdh8,1807
|
|
8
8
|
hestia_earth/utils/descriptive_stats.py,sha256=EMVwFvg2OnZgKRAfireAoWY2EbrSvqR0V0bK9B53p28,1583
|
|
9
9
|
hestia_earth/utils/emission.py,sha256=crHAJOQRI0NRHht0fFOFjEqcarsFqzbV4pDgk90dfME,1595
|
|
10
|
-
hestia_earth/utils/lookup.py,sha256=
|
|
10
|
+
hestia_earth/utils/lookup.py,sha256=0RLqy3HPzkbhkRaO7fYoHU0jKhAYzI6QHMptMEbqTlg,10344
|
|
11
11
|
hestia_earth/utils/lookup_utils.py,sha256=9pkJUKo3NEBspoN9yRPoDCzkxcbpnbLpC7Z0I6HiP7I,5369
|
|
12
12
|
hestia_earth/utils/model.py,sha256=uUcrF07XmBzqLni8VSaP0HoebJnQ57kk0EOmhwYMbfI,4637
|
|
13
|
-
hestia_earth/utils/pipeline.py,sha256=
|
|
13
|
+
hestia_earth/utils/pipeline.py,sha256=mQeGffV3-2_jI-m_8TZB_entAbFRci3vNl9BYdayLv0,9198
|
|
14
14
|
hestia_earth/utils/request.py,sha256=bu7hkWKmFdXl2_Feawiam_x32whlclA9oP0asJyC69k,626
|
|
15
15
|
hestia_earth/utils/stats.py,sha256=4t3op10xDJbGxWJEY1Jtyl302PYWyMFwLpsSkMlzQn8,34667
|
|
16
16
|
hestia_earth/utils/table.py,sha256=RrTt-KF_QzjKiCpaAueoG6La1FG-Iusxw5NMDpoRBpQ,2861
|
|
17
|
+
hestia_earth/utils/term.py,sha256=6LiUSc6KX3IOkfWF6fYkQ2tENCO8ENljcdDypxU6WtA,1060
|
|
17
18
|
hestia_earth/utils/tools.py,sha256=eCppZ0gFR6RPF7TEraMLwLJnUCJb93xP0iEzFPcYpK0,4685
|
|
18
|
-
hestia_earth/utils/version.py,sha256=
|
|
19
|
+
hestia_earth/utils/version.py,sha256=wfstim2Kb8lTIW3BkKHomKCdWgFQuGpqTdKGYJFloNc,19
|
|
19
20
|
hestia_earth/utils/pivot/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
20
21
|
hestia_earth/utils/pivot/_shared.py,sha256=sRE_PGe9u0-sFnCb0mdeM7vPOkFWt3-kDs8WSGQTQGk,875
|
|
21
22
|
hestia_earth/utils/pivot/pivot_csv.py,sha256=Ed-sCKEqVIFJu71AncS7zlMkHbw5V15QLd5c5B_uxiE,12296
|
|
@@ -25,12 +26,12 @@ hestia_earth/utils/storage/_azure_client.py,sha256=sevCZni04eknMql2DgUsWG23f7u0K
|
|
|
25
26
|
hestia_earth/utils/storage/_local_client.py,sha256=IbzziUKY0QS3ybHFfgEpELqvafa7hQnZ-DdGdjQuypE,515
|
|
26
27
|
hestia_earth/utils/storage/_s3_client.py,sha256=sR_HkvNmDFpLYislSUw1nffHicznCcPo1p_5cve2ExU,2216
|
|
27
28
|
hestia_earth/utils/storage/_sns_client.py,sha256=LowUatj78Egu6_Id6Rr7hZjfZx1WguS3lozB3yAwSps,347
|
|
28
|
-
hestia_earth_utils-0.15.
|
|
29
|
-
hestia_earth_utils-0.15.
|
|
29
|
+
hestia_earth_utils-0.15.4.data/scripts/hestia-format-upload,sha256=IhLAHHPJqRgUcht-M_EUEsRMbRbMfshig07o488zscM,703
|
|
30
|
+
hestia_earth_utils-0.15.4.data/scripts/hestia-pivot-csv,sha256=0YBuGuyPO8rytod6iwWEKiQdSlr9JLuD001k6U5t6no,1163
|
|
30
31
|
tests/pivot/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
31
32
|
tests/pivot/test_pivot_csv.py,sha256=aYni7o3QDPSgtVxVCspEetotgpYHY7Lz5VHf-DR89gw,8131
|
|
32
33
|
tests/pivot/test_pivot_json.py,sha256=UYTAN4AZhzVicIYsU1A2VgJcctUXohjHppg6s-pqwcg,8287
|
|
33
|
-
hestia_earth_utils-0.15.
|
|
34
|
-
hestia_earth_utils-0.15.
|
|
35
|
-
hestia_earth_utils-0.15.
|
|
36
|
-
hestia_earth_utils-0.15.
|
|
34
|
+
hestia_earth_utils-0.15.4.dist-info/METADATA,sha256=uQOWL4blG7K_tv2SfIQ427ZsVXdvjStPk5fkgpUU-Es,1757
|
|
35
|
+
hestia_earth_utils-0.15.4.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
|
36
|
+
hestia_earth_utils-0.15.4.dist-info/top_level.txt,sha256=1dqA9TqpOLTEgpqa-YBsmbCmmNU1y56AtfFGEceZ2A0,19
|
|
37
|
+
hestia_earth_utils-0.15.4.dist-info/RECORD,,
|
{hestia_earth_utils-0.15.2.data → hestia_earth_utils-0.15.4.data}/scripts/hestia-format-upload
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|