hestia-earth-utils 0.15.12__tar.gz → 0.15.14__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.15.12 → hestia_earth_utils-0.15.14}/PKG-INFO +1 -1
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/pivot/_shared.py +16 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/pivot/pivot_csv.py +2 -2
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/pivot/pivot_json.py +10 -10
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/storage/_s3_client.py +11 -7
- hestia_earth_utils-0.15.14/hestia_earth/utils/version.py +1 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth_utils.egg-info/PKG-INFO +1 -1
- hestia_earth_utils-0.15.12/hestia_earth/utils/version.py +0 -1
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/MANIFEST.in +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/README.md +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/bin/hestia-format-upload +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/bin/hestia-pivot-csv +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/__init__.py +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/__init__.py +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/api.py +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/blank_node.py +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/calculation_status.py +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/cycle.py +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/date.py +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/descriptive_stats.py +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/emission.py +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/lookup.py +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/lookup_utils.py +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/model.py +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/pipeline.py +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/pivot/__init__.py +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/request.py +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/stats.py +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/storage/__init__.py +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/storage/_azure_client.py +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/storage/_local_client.py +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/storage/_sns_client.py +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/table.py +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/term.py +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/tools.py +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth_utils.egg-info/SOURCES.txt +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth_utils.egg-info/dependency_links.txt +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth_utils.egg-info/requires.txt +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth_utils.egg-info/top_level.txt +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/setup.cfg +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/setup.py +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/tests/pivot/__init__.py +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/tests/pivot/test_pivot_csv.py +0 -0
- {hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/tests/pivot/test_pivot_json.py +0 -0
{hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/pivot/_shared.py
RENAMED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import json
|
|
2
2
|
import numpy as np
|
|
3
|
+
from hestia_earth.schema import EmissionMethodTier
|
|
3
4
|
|
|
4
5
|
|
|
5
6
|
EXCLUDE_FIELDS = ["@type", "type", "@context"]
|
|
@@ -33,3 +34,18 @@ def _is_scalar_list(value):
|
|
|
33
34
|
all_scalar = False
|
|
34
35
|
break
|
|
35
36
|
return all_scalar
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _filter_not_relevant(blank_node: dict):
|
|
40
|
+
return blank_node.get('methodTier') != EmissionMethodTier.NOT_RELEVANT.value
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _filter_emissions_not_relevant(node: dict):
|
|
44
|
+
"""
|
|
45
|
+
Ignore all emissions where `methodTier=not relevant` so save space.
|
|
46
|
+
"""
|
|
47
|
+
return node | ({
|
|
48
|
+
key: list(filter(_filter_not_relevant, node[key]))
|
|
49
|
+
for key in ['emissions', 'emissionsResourceUse']
|
|
50
|
+
if key in node
|
|
51
|
+
})
|
{hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/pivot/pivot_csv.py
RENAMED
|
@@ -8,7 +8,7 @@ from flatten_json import flatten as flatten_json
|
|
|
8
8
|
|
|
9
9
|
# __package__ = "hestia_earth.utils" # required to run interactively in vscode
|
|
10
10
|
from ..api import find_term_ids_by_names
|
|
11
|
-
from ._shared import EXCLUDE_FIELDS, EXCLUDE_PRIVATE_FIELDS, _with_csv_formatting
|
|
11
|
+
from ._shared import EXCLUDE_FIELDS, EXCLUDE_PRIVATE_FIELDS, _with_csv_formatting, _filter_emissions_not_relevant
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
PANDAS_IMPORT_ERROR_MSG = "Run `pip install pandas>=1.2` to use this functionality"
|
|
@@ -293,7 +293,7 @@ def pivot_nodes(nodes: list[dict]):
|
|
|
293
293
|
Pivot array of nodes in dict format (e.g under the 'nodes' key of a .hestia file)
|
|
294
294
|
The nodes json should first be parsed using _with_csv_formatting for output as csv.
|
|
295
295
|
"""
|
|
296
|
-
df_in = nodes_to_df(nodes)
|
|
296
|
+
df_in = nodes_to_df(list(map(_filter_emissions_not_relevant, nodes)))
|
|
297
297
|
|
|
298
298
|
regex = rf".*\.({'|'.join(EXCLUDE_FIELDS + EXCLUDE_PRIVATE_FIELDS)})$"
|
|
299
299
|
df_in.drop(df_in.filter(regex=regex).columns, axis=1, inplace=True)
|
{hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/pivot/pivot_json.py
RENAMED
|
@@ -5,7 +5,8 @@ from flatten_json import flatten, unflatten_list
|
|
|
5
5
|
from collections import defaultdict
|
|
6
6
|
from copy import deepcopy
|
|
7
7
|
|
|
8
|
-
from .
|
|
8
|
+
from hestia_earth.utils.pipeline import _node_type
|
|
9
|
+
from ._shared import EXCLUDE_FIELDS, EXCLUDE_PRIVATE_FIELDS, _with_csv_formatting, _filter_emissions_not_relevant
|
|
9
10
|
|
|
10
11
|
pivot_exclude_fields = Term().fields
|
|
11
12
|
pivot_exclude_fields.update({k: "" for k in EXCLUDE_FIELDS} | {k: "" for k in EXCLUDE_PRIVATE_FIELDS})
|
|
@@ -52,7 +53,7 @@ def _base_pivoted_value(key: str, value, is_top_level: bool):
|
|
|
52
53
|
|
|
53
54
|
def _do_pivot(node, parent_node_type=None, parent_field=None, level=0): # noqa: C901
|
|
54
55
|
# print('\ninput node', level, node, '\n')
|
|
55
|
-
node_type =
|
|
56
|
+
node_type = _node_type(node)
|
|
56
57
|
if node_type not in ADAPTED_UNIQUENESS_FIELDS:
|
|
57
58
|
return node
|
|
58
59
|
pivoted_node = {
|
|
@@ -206,6 +207,13 @@ def _do_pivot(node, parent_node_type=None, parent_field=None, level=0): # noqa:
|
|
|
206
207
|
return pivoted_node
|
|
207
208
|
|
|
208
209
|
|
|
210
|
+
def pivot_node(node: dict):
|
|
211
|
+
"""
|
|
212
|
+
Pivot single node in dict format parsed with object_hook=_with_csv_formatting
|
|
213
|
+
"""
|
|
214
|
+
return _do_pivot(_filter_emissions_not_relevant(node))
|
|
215
|
+
|
|
216
|
+
|
|
209
217
|
def pivot_json_node(json_node: str):
|
|
210
218
|
"""
|
|
211
219
|
Pivot single schema-compliant unparsed json string node
|
|
@@ -227,11 +235,3 @@ def pivot_nodes(nodes: list[dict]):
|
|
|
227
235
|
Pivot multiple nodes in dict format parsed with object_hook=_with_csv_formatting
|
|
228
236
|
"""
|
|
229
237
|
return [pivot_node(node) for node in nodes]
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
def pivot_node(node: dict):
|
|
233
|
-
"""
|
|
234
|
-
Pivot single node in dict format parsed with object_hook=_with_csv_formatting
|
|
235
|
-
"""
|
|
236
|
-
pivoted_node = _do_pivot(node)
|
|
237
|
-
return pivoted_node
|
{hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/storage/_s3_client.py
RENAMED
|
@@ -100,12 +100,16 @@ def _list_bucket_objects(bucket: str, folder: str = ''):
|
|
|
100
100
|
def _delete_objects(bucket: str, objects: list):
|
|
101
101
|
from botocore.exceptions import ClientError
|
|
102
102
|
try:
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
103
|
+
# delete in batch of 1000 max allowed
|
|
104
|
+
batch_size = 1000
|
|
105
|
+
for i in range(0, len(objects), batch_size):
|
|
106
|
+
batch_objects = objects[i:i + batch_size]
|
|
107
|
+
_get_s3_client().delete_objects(
|
|
108
|
+
Bucket=bucket,
|
|
109
|
+
Delete={
|
|
110
|
+
'Objects': batch_objects,
|
|
111
|
+
'Quiet': True
|
|
112
|
+
}
|
|
113
|
+
)
|
|
110
114
|
except ClientError:
|
|
111
115
|
return None
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
VERSION = '0.15.14'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
VERSION = '0.15.12'
|
|
File without changes
|
|
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.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/calculation_status.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/descriptive_stats.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/lookup_utils.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/pivot/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/storage/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth/utils/storage/_sns_client.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth_utils.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/hestia_earth_utils.egg-info/requires.txt
RENAMED
|
File without changes
|
{hestia_earth_utils-0.15.12 → hestia_earth_utils-0.15.14}/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
|