matrix-utils 0.6__tar.gz → 0.6.3__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.
- {matrix_utils-0.6 → matrix_utils-0.6.3}/CHANGELOG.md +15 -2
- {matrix_utils-0.6 → matrix_utils-0.6.3}/PKG-INFO +3 -2
- matrix_utils-0.6.3/matrix_utils/__init__.py +20 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/matrix_utils/array_mapper.py +2 -2
- {matrix_utils-0.6 → matrix_utils-0.6.3}/matrix_utils/mapped_matrix.py +36 -17
- {matrix_utils-0.6 → matrix_utils-0.6.3}/matrix_utils/mapped_matrix_dict.py +5 -4
- {matrix_utils-0.6 → matrix_utils-0.6.3}/matrix_utils/resource_group.py +17 -4
- {matrix_utils-0.6 → matrix_utils-0.6.3}/matrix_utils/utils.py +51 -1
- {matrix_utils-0.6 → matrix_utils-0.6.3}/matrix_utils.egg-info/PKG-INFO +3 -2
- {matrix_utils-0.6 → matrix_utils-0.6.3}/tests/mapped_matrix.py +9 -1
- {matrix_utils-0.6 → matrix_utils-0.6.3}/tests/utils.py +53 -1
- matrix_utils-0.6/matrix_utils/__init__.py +0 -20
- {matrix_utils-0.6 → matrix_utils-0.6.3}/.gitignore +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/.pre-commit-config.yaml +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/CODE_OF_CONDUCT.md +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/LICENSE +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/MANIFEST.in +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/README.md +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/binder/Brightway 2.5 demonstration.ipynb +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/binder/environment.yml +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/dev/Brightway 2.5 - Linking with IAMs.ipynb +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/dev/Brightway 2.5 demonstration.ipynb +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/dev/Graph traversal with modification.ipynb +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/dev/Indexing speed tests.ipynb +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/dev/Interfaces which produce results for multiple matrices.ipynb +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/dev/Mapping speed tests.ipynb +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/dev/Multifunctionality with Brightway 2.5.ipynb +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/dev/Real-time modification of hybrid databases.ipynb +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/dev/Supply chain modification.ipynb +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/dev/Untitled.ipynb +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/dev/profiling/bw2.prof +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/dev/profiling/bw2.svg +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/dev/profiling/bw25.prof +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/dev/profiling/bw25.svg +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/dev/profiling/bw25_profile.txt +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/dev/profiling/bw25_profiling.py +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/dev/profiling/bw2_profile.txt +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/dev/profiling/bw2_profiling.py +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/dev/profiling/profiling-versus-bw2.py +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/dev/speed_test_unique_indices.py +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/dev/speed_tests.py +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/docs/Makefile +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/docs/conf.py +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/docs/index.rst +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/docs/loading.rst +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/docs/make.bat +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/docs/saving.rst +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/docs/utilities.rst +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/matrix_utils/aggregation.py +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/matrix_utils/errors.py +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/matrix_utils/indexers.py +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/matrix_utils.egg-info/SOURCES.txt +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/matrix_utils.egg-info/dependency_links.txt +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/matrix_utils.egg-info/requires.txt +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/matrix_utils.egg-info/top_level.txt +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/pyproject.toml +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/setup.cfg +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/tests/array_mapper.py +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/tests/fixtures/__init__.py +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/tests/fixtures/a-first.zip +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/tests/fixtures/b-second.zip +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/tests/fixtures/basic.py +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/tests/fixtures/create_static_fixtures.py +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/tests/fixtures/sa-1.zip +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/tests/fixtures/sa-2.zip +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/tests/indexers.py +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/tests/integration.py +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/tests/interfaces.py +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/tests/masking.py +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/tests/monte_carlo.py +0 -0
- {matrix_utils-0.6 → matrix_utils-0.6.3}/tests/ordering.py +0 -0
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
### [0.6] -
|
|
3
|
+
### [0.6.3] - 2026-02-23
|
|
4
|
+
|
|
5
|
+
* Fix [#32](https://github.com/brightway-lca/matrix_utils/issues/32): Replace deprecated `.A1` property on scipy sparse matrices
|
|
6
|
+
|
|
7
|
+
### [0.6.2] - 2025-08-06
|
|
8
|
+
|
|
9
|
+
* Fix [#27](https://github.com/brightway-lca/matrix_utils/issues/27): Release `0.6.1` broke Python `3.9` compatibility
|
|
10
|
+
|
|
11
|
+
### [0.6.1] - 2025-08-06
|
|
12
|
+
|
|
13
|
+
* Fix [#26](https://github.com/brightway-lca/matrix_utils/issues/26): `AllArraysEmpty` error is incomprehensible
|
|
14
|
+
* Switch to absolute internal imports
|
|
15
|
+
|
|
16
|
+
## [0.6] - 2024-11-01
|
|
4
17
|
|
|
5
18
|
* New array mapping implementation using sparse matrices which is ~100x faster and allows for very large input values
|
|
6
19
|
|
|
7
|
-
|
|
20
|
+
## [0.5] - 2024-08-20
|
|
8
21
|
|
|
9
22
|
* Default is now 64 bit integers for indexing; compatible with `bw_processing` 1.0
|
|
10
23
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: matrix_utils
|
|
3
|
-
Version: 0.6
|
|
3
|
+
Version: 0.6.3
|
|
4
4
|
Summary: Tools to create matrices from data packages
|
|
5
5
|
Author-email: Chris Mutel <cmutel@gmail.com>
|
|
6
6
|
Maintainer-email: Chris Mutel <cmutel@gmail.com>
|
|
@@ -43,6 +43,7 @@ Requires-Dist: pylint; extra == "dev"
|
|
|
43
43
|
Requires-Dist: pytest; extra == "dev"
|
|
44
44
|
Requires-Dist: pytest-cov; extra == "dev"
|
|
45
45
|
Requires-Dist: setuptools; extra == "dev"
|
|
46
|
+
Dynamic: license-file
|
|
46
47
|
|
|
47
48
|
# matrix_utils
|
|
48
49
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
__all__ = (
|
|
2
|
+
"__version__",
|
|
3
|
+
"ArrayMapper",
|
|
4
|
+
"CombinatorialIndexer",
|
|
5
|
+
"MappedMatrix",
|
|
6
|
+
"MappedMatrixDict",
|
|
7
|
+
"Proxy",
|
|
8
|
+
"RandomIndexer",
|
|
9
|
+
"ResourceGroup",
|
|
10
|
+
"SequentialIndexer",
|
|
11
|
+
"SparseMatrixDict",
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
__version__ = "0.6.3"
|
|
15
|
+
|
|
16
|
+
from matrix_utils.array_mapper import ArrayMapper
|
|
17
|
+
from matrix_utils.indexers import CombinatorialIndexer, Proxy, RandomIndexer, SequentialIndexer
|
|
18
|
+
from matrix_utils.mapped_matrix import MappedMatrix
|
|
19
|
+
from matrix_utils.mapped_matrix_dict import MappedMatrixDict, SparseMatrixDict
|
|
20
|
+
from matrix_utils.resource_group import ResourceGroup
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import numpy as np
|
|
2
2
|
from scipy import sparse
|
|
3
3
|
|
|
4
|
-
from .errors import EmptyArray
|
|
4
|
+
from matrix_utils.errors import EmptyArray
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
class ArrayMapper:
|
|
@@ -75,7 +75,7 @@ class ArrayMapper:
|
|
|
75
75
|
result = np.zeros_like(array) - 1
|
|
76
76
|
mask = array <= self.max_value
|
|
77
77
|
# https://numpy.org/doc/stable/reference/generated/numpy.matrix.A1.html
|
|
78
|
-
result[mask] = (self.matrix[array[mask], np.zeros_like(array[mask])]).
|
|
78
|
+
result[mask] = np.asarray(self.matrix[array[mask], np.zeros_like(array[mask])]).ravel() - 1
|
|
79
79
|
return result
|
|
80
80
|
|
|
81
81
|
def to_dict(self) -> dict:
|
|
@@ -4,11 +4,15 @@ import numpy as np
|
|
|
4
4
|
from bw_processing import INDICES_DTYPE, UNCERTAINTY_DTYPE, Datapackage
|
|
5
5
|
from scipy import sparse
|
|
6
6
|
|
|
7
|
-
from .array_mapper import ArrayMapper
|
|
8
|
-
from .errors import EmptyInterface
|
|
9
|
-
from .indexers import CombinatorialIndexer, RandomIndexer, SequentialIndexer
|
|
10
|
-
from .resource_group import ResourceGroup
|
|
11
|
-
from .utils import
|
|
7
|
+
from matrix_utils.array_mapper import ArrayMapper
|
|
8
|
+
from matrix_utils.errors import AllArraysEmpty, EmptyInterface
|
|
9
|
+
from matrix_utils.indexers import CombinatorialIndexer, RandomIndexer, SequentialIndexer
|
|
10
|
+
from matrix_utils.resource_group import ResourceGroup
|
|
11
|
+
from matrix_utils.utils import (
|
|
12
|
+
filter_groups_for_packages,
|
|
13
|
+
handle_all_arrays_empty,
|
|
14
|
+
safe_concatenate_indices,
|
|
15
|
+
)
|
|
12
16
|
|
|
13
17
|
|
|
14
18
|
class MappedMatrix:
|
|
@@ -17,6 +21,7 @@ class MappedMatrix:
|
|
|
17
21
|
*,
|
|
18
22
|
packages: Sequence[Datapackage],
|
|
19
23
|
matrix: str,
|
|
24
|
+
identifier: Optional[str] = None,
|
|
20
25
|
use_vectors: bool = True,
|
|
21
26
|
use_arrays: bool = True,
|
|
22
27
|
use_distributions: bool = False,
|
|
@@ -109,20 +114,25 @@ class MappedMatrix:
|
|
|
109
114
|
self.groups = tuple([obj for lst in self.packages.values() for obj in lst])
|
|
110
115
|
self.add_indexers(indexer_override, seed_override)
|
|
111
116
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
[obj.unique_row_indices_for_mapping() for obj in self.groups], empty_ok
|
|
115
|
-
),
|
|
116
|
-
empty_ok=empty_ok,
|
|
117
|
-
)
|
|
118
|
-
if not diagonal:
|
|
119
|
-
self.col_mapper = col_mapper or ArrayMapper(
|
|
117
|
+
try:
|
|
118
|
+
self.row_mapper = row_mapper or ArrayMapper(
|
|
120
119
|
array=safe_concatenate_indices(
|
|
121
|
-
[obj.
|
|
122
|
-
empty_ok,
|
|
120
|
+
[obj.unique_row_indices_for_mapping() for obj in self.groups], empty_ok
|
|
123
121
|
),
|
|
124
122
|
empty_ok=empty_ok,
|
|
125
123
|
)
|
|
124
|
+
if not diagonal:
|
|
125
|
+
self.col_mapper = col_mapper or ArrayMapper(
|
|
126
|
+
array=safe_concatenate_indices(
|
|
127
|
+
[obj.unique_col_indices_for_mapping() for obj in self.groups],
|
|
128
|
+
empty_ok,
|
|
129
|
+
),
|
|
130
|
+
empty_ok=empty_ok,
|
|
131
|
+
)
|
|
132
|
+
except AllArraysEmpty:
|
|
133
|
+
handle_all_arrays_empty(
|
|
134
|
+
packages=self.packages, matrix_label=self.matrix_label, identifier=identifier
|
|
135
|
+
)
|
|
126
136
|
|
|
127
137
|
self.add_mappers(
|
|
128
138
|
axis=0,
|
|
@@ -133,8 +143,17 @@ class MappedMatrix:
|
|
|
133
143
|
self.add_mappers(axis=1, mapper=self.col_mapper)
|
|
134
144
|
self.map_indices()
|
|
135
145
|
|
|
136
|
-
|
|
137
|
-
|
|
146
|
+
try:
|
|
147
|
+
row_indices = safe_concatenate_indices(
|
|
148
|
+
[obj.row_matrix for obj in self.groups], empty_ok
|
|
149
|
+
)
|
|
150
|
+
col_indices = safe_concatenate_indices(
|
|
151
|
+
[obj.col_matrix for obj in self.groups], empty_ok
|
|
152
|
+
)
|
|
153
|
+
except AllArraysEmpty:
|
|
154
|
+
handle_all_arrays_empty(
|
|
155
|
+
packages=self.packages, matrix_label=self.matrix_label, identifier=identifier
|
|
156
|
+
)
|
|
138
157
|
|
|
139
158
|
if diagonal:
|
|
140
159
|
x = 0 if self.row_mapper.empty_input else self.row_mapper.max_index + 1
|
|
@@ -4,10 +4,10 @@ from typing import Any, Callable, Optional, Sequence, Type, Union
|
|
|
4
4
|
from bw_processing import Datapackage
|
|
5
5
|
from scipy import sparse
|
|
6
6
|
|
|
7
|
-
from .array_mapper import ArrayMapper
|
|
8
|
-
from .indexers import Indexer, RandomIndexer, SequentialIndexer
|
|
9
|
-
from .mapped_matrix import MappedMatrix
|
|
10
|
-
from .utils import unroll
|
|
7
|
+
from matrix_utils.array_mapper import ArrayMapper
|
|
8
|
+
from matrix_utils.indexers import Indexer, RandomIndexer, SequentialIndexer
|
|
9
|
+
from matrix_utils.mapped_matrix import MappedMatrix
|
|
10
|
+
from matrix_utils.utils import unroll
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
class SparseMatrixDict(dict):
|
|
@@ -133,6 +133,7 @@ class MappedMatrixDict(Mapping):
|
|
|
133
133
|
key: matrix_class(
|
|
134
134
|
packages=packages,
|
|
135
135
|
matrix=matrix,
|
|
136
|
+
identifier=str(key),
|
|
136
137
|
use_vectors=use_vectors,
|
|
137
138
|
use_arrays=use_arrays,
|
|
138
139
|
use_distributions=use_distributions,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
from typing import Any, Callable, Union
|
|
1
|
+
from typing import Any, Callable, Optional, Union
|
|
2
2
|
|
|
3
3
|
import numpy as np
|
|
4
4
|
from bw_processing import DatapackageBase
|
|
5
5
|
from stats_arrays import MCRandomNumberGenerator
|
|
6
6
|
|
|
7
|
-
from .aggregation import aggregate_with_sparse
|
|
8
|
-
from .array_mapper import ArrayMapper
|
|
9
|
-
from .indexers import Indexer, Proxy
|
|
7
|
+
from matrix_utils.aggregation import aggregate_with_sparse
|
|
8
|
+
from matrix_utils.array_mapper import ArrayMapper
|
|
9
|
+
from matrix_utils.indexers import Indexer, Proxy
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class FakeRNG:
|
|
@@ -96,6 +96,19 @@ class ResourceGroup:
|
|
|
96
96
|
bool(self.custom_filter),
|
|
97
97
|
)
|
|
98
98
|
|
|
99
|
+
@property
|
|
100
|
+
def identifier(self) -> Optional[str]:
|
|
101
|
+
"""Shortcut to get a single `identifier` attribute for the group resources"""
|
|
102
|
+
ids = {
|
|
103
|
+
group["identifier"]
|
|
104
|
+
for group in self.package.metadata["resources"]
|
|
105
|
+
if group.get("identifier")
|
|
106
|
+
}
|
|
107
|
+
if not ids or len(ids) > 1:
|
|
108
|
+
return None
|
|
109
|
+
else:
|
|
110
|
+
return ids.pop()
|
|
111
|
+
|
|
99
112
|
@property
|
|
100
113
|
def has_distributions(self):
|
|
101
114
|
try:
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
1
3
|
import numpy as np
|
|
2
4
|
|
|
3
|
-
from .errors import AllArraysEmpty
|
|
5
|
+
from matrix_utils.errors import AllArraysEmpty
|
|
4
6
|
|
|
5
7
|
|
|
6
8
|
def filter_groups_for_packages(
|
|
@@ -62,3 +64,51 @@ def unroll(a: tuple, b: tuple) -> tuple:
|
|
|
62
64
|
return (a, *b)
|
|
63
65
|
else:
|
|
64
66
|
return (a, b)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def handle_all_arrays_empty(
|
|
70
|
+
packages: dict, matrix_label: str, identifier: Optional[str] = None
|
|
71
|
+
) -> None:
|
|
72
|
+
"""Format the error messages for `AllArraysEmpty` to make them understandable"""
|
|
73
|
+
if not packages and not identifier:
|
|
74
|
+
ERROR = """
|
|
75
|
+
No data found to build {} matrix.
|
|
76
|
+
|
|
77
|
+
No datapackages found which could provide data to build this matrix.
|
|
78
|
+
""".format(
|
|
79
|
+
matrix_label
|
|
80
|
+
)
|
|
81
|
+
raise AllArraysEmpty(ERROR)
|
|
82
|
+
elif not packages:
|
|
83
|
+
ERROR = """
|
|
84
|
+
No data found to build {} matrix for {}.
|
|
85
|
+
|
|
86
|
+
No datapackages found which could provide data to build this matrix.
|
|
87
|
+
""".format(
|
|
88
|
+
matrix_label, identifier
|
|
89
|
+
)
|
|
90
|
+
raise AllArraysEmpty(ERROR)
|
|
91
|
+
else:
|
|
92
|
+
ERROR_START = """
|
|
93
|
+
No data found to build {} matrix.
|
|
94
|
+
|
|
95
|
+
This error commonly occurs when using impact assessment methods for the wrong version of the
|
|
96
|
+
background database, because each background database version has its own set of elementary flows.
|
|
97
|
+
|
|
98
|
+
Found {} resource groups in {} datapackages but none of them had data for the requested method:
|
|
99
|
+
""".format(
|
|
100
|
+
matrix_label, len(packages), sum(len(group) for group in packages.values())
|
|
101
|
+
)
|
|
102
|
+
ERROR_DETAIL_TEMPLATE = """
|
|
103
|
+
Datapackage name: {}
|
|
104
|
+
Resource group: {}
|
|
105
|
+
Data array length: {} (none of this data could be used)
|
|
106
|
+
"""
|
|
107
|
+
ERROR_DETAILS = [
|
|
108
|
+
ERROR_DETAIL_TEMPLATE.format(
|
|
109
|
+
package.metadata["name"], group.identifier or group.label, len(group.data_original)
|
|
110
|
+
)
|
|
111
|
+
for package, groups in packages.items()
|
|
112
|
+
for group in groups
|
|
113
|
+
]
|
|
114
|
+
raise AllArraysEmpty(ERROR_START + "".join(ERROR_DETAILS))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: matrix_utils
|
|
3
|
-
Version: 0.6
|
|
3
|
+
Version: 0.6.3
|
|
4
4
|
Summary: Tools to create matrices from data packages
|
|
5
5
|
Author-email: Chris Mutel <cmutel@gmail.com>
|
|
6
6
|
Maintainer-email: Chris Mutel <cmutel@gmail.com>
|
|
@@ -43,6 +43,7 @@ Requires-Dist: pylint; extra == "dev"
|
|
|
43
43
|
Requires-Dist: pytest; extra == "dev"
|
|
44
44
|
Requires-Dist: pytest-cov; extra == "dev"
|
|
45
45
|
Requires-Dist: setuptools; extra == "dev"
|
|
46
|
+
Dynamic: license-file
|
|
46
47
|
|
|
47
48
|
# matrix_utils
|
|
48
49
|
|
|
@@ -142,11 +142,19 @@ def test_indexer_override():
|
|
|
142
142
|
|
|
143
143
|
|
|
144
144
|
def test_no_packages_error():
|
|
145
|
-
with pytest.raises(AllArraysEmpty):
|
|
145
|
+
with pytest.raises(AllArraysEmpty) as exc_info:
|
|
146
146
|
MappedMatrix(
|
|
147
147
|
packages=[],
|
|
148
148
|
matrix="foo",
|
|
149
149
|
)
|
|
150
|
+
assert (
|
|
151
|
+
exc_info.value.args[0]
|
|
152
|
+
== """
|
|
153
|
+
No data found to build foo matrix.
|
|
154
|
+
|
|
155
|
+
No datapackages found which could provide data to build this matrix.
|
|
156
|
+
"""
|
|
157
|
+
)
|
|
150
158
|
|
|
151
159
|
|
|
152
160
|
def test_no_packages_empty_ok():
|
|
@@ -3,7 +3,13 @@ import numpy as np
|
|
|
3
3
|
import pytest
|
|
4
4
|
|
|
5
5
|
from matrix_utils.errors import AllArraysEmpty
|
|
6
|
-
from matrix_utils.
|
|
6
|
+
from matrix_utils.resource_group import ResourceGroup
|
|
7
|
+
from matrix_utils.utils import (
|
|
8
|
+
handle_all_arrays_empty,
|
|
9
|
+
has_relevant_data,
|
|
10
|
+
safe_concatenate_indices,
|
|
11
|
+
unroll,
|
|
12
|
+
)
|
|
7
13
|
|
|
8
14
|
|
|
9
15
|
def test_safe_concatenate_indices():
|
|
@@ -103,3 +109,49 @@ def test_tuple_unrolling():
|
|
|
103
109
|
"wild",
|
|
104
110
|
"wacky",
|
|
105
111
|
)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def test_handle_all_arrays_empty_multiple():
|
|
115
|
+
a = bwp.create_datapackage(name="abcd")
|
|
116
|
+
a.add_persistent_vector(
|
|
117
|
+
matrix="foo-matrix",
|
|
118
|
+
name="first-one",
|
|
119
|
+
indices_array=np.array([(10, 10), (12, 9), (14, 8), (18, 7)], dtype=bwp.INDICES_DTYPE),
|
|
120
|
+
data_array=np.array([11, 12.3, 14, 125]),
|
|
121
|
+
)
|
|
122
|
+
a = a.filter_by_attribute("matrix", "foo-matrix")
|
|
123
|
+
|
|
124
|
+
b = bwp.create_datapackage(name="efgh")
|
|
125
|
+
b.add_persistent_vector(
|
|
126
|
+
matrix="foo-matrix",
|
|
127
|
+
name="second-one",
|
|
128
|
+
indices_array=np.array([(10, 10), (12, 9), (14, 8)], dtype=bwp.INDICES_DTYPE),
|
|
129
|
+
data_array=np.array([11, 12.3, 14]),
|
|
130
|
+
)
|
|
131
|
+
b = b.filter_by_attribute("matrix", "foo-matrix")
|
|
132
|
+
|
|
133
|
+
packages = {
|
|
134
|
+
a: [ResourceGroup(package=a, group_label="first-one")],
|
|
135
|
+
b: [ResourceGroup(package=b, group_label="second-one")],
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
with pytest.raises(AllArraysEmpty) as exc_info:
|
|
139
|
+
handle_all_arrays_empty(packages, "foo-matrix")
|
|
140
|
+
|
|
141
|
+
expected = """
|
|
142
|
+
No data found to build foo-matrix matrix.
|
|
143
|
+
|
|
144
|
+
This error commonly occurs when using impact assessment methods for the wrong version of the
|
|
145
|
+
background database, because each background database version has its own set of elementary flows.
|
|
146
|
+
|
|
147
|
+
Found 2 resource groups in 2 datapackages but none of them had data for the requested method:
|
|
148
|
+
|
|
149
|
+
Datapackage name: abcd
|
|
150
|
+
Resource group: first-one
|
|
151
|
+
Data array length: 4 (none of this data could be used)
|
|
152
|
+
|
|
153
|
+
Datapackage name: efgh
|
|
154
|
+
Resource group: second-one
|
|
155
|
+
Data array length: 3 (none of this data could be used)
|
|
156
|
+
"""
|
|
157
|
+
assert exc_info.value.args[0] == expected
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
__all__ = (
|
|
2
|
-
"__version__",
|
|
3
|
-
"ArrayMapper",
|
|
4
|
-
"CombinatorialIndexer",
|
|
5
|
-
"MappedMatrix",
|
|
6
|
-
"MappedMatrixDict",
|
|
7
|
-
"Proxy",
|
|
8
|
-
"RandomIndexer",
|
|
9
|
-
"ResourceGroup",
|
|
10
|
-
"SequentialIndexer",
|
|
11
|
-
"SparseMatrixDict",
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
__version__ = "0.6"
|
|
15
|
-
|
|
16
|
-
from .array_mapper import ArrayMapper
|
|
17
|
-
from .indexers import CombinatorialIndexer, Proxy, RandomIndexer, SequentialIndexer
|
|
18
|
-
from .mapped_matrix import MappedMatrix
|
|
19
|
-
from .mapped_matrix_dict import MappedMatrixDict, SparseMatrixDict
|
|
20
|
-
from .resource_group import ResourceGroup
|
|
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
|
{matrix_utils-0.6 → matrix_utils-0.6.3}/dev/Real-time modification of hybrid databases.ipynb
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
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|