bw-processing 1.1__tar.gz → 1.1.1__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.
- {bw_processing-1.1/src/bw_processing.egg-info → bw_processing-1.1.1}/PKG-INFO +1 -1
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing/__init__.py +1 -1
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing/matrix_entry.py +16 -0
- {bw_processing-1.1 → bw_processing-1.1.1/src/bw_processing.egg-info}/PKG-INFO +1 -1
- {bw_processing-1.1 → bw_processing-1.1.1}/tests/test_matrix_entry.py +21 -1
- {bw_processing-1.1 → bw_processing-1.1.1}/LICENSE +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/MANIFEST.in +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/README.md +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/pyproject.toml +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/setup.cfg +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing/array_creation.py +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing/constants.py +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing/datapackage.py +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing/errors.py +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing/examples/__init__.py +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing/examples/datapackage_1/another name.indices.parquet +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing/examples/datapackage_1/sa-data-vector-from-dict.data.parquet +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing/examples/datapackage_1/sa-data-vector-from-dict.distributions.parquet +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing/examples/datapackage_1/sa-data-vector-from-dict.flip.parquet +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing/examples/datapackage_1/sa-data-vector-from-dict.indices.parquet +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing/examples/datapackage_1/some name.data.parquet +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing/examples/datapackage_1/some name.flip.parquet +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing/examples/datapackage_1/some name.indices.parquet +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing/examples/datapackage_2.zip +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing/examples/interfaces.py +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing/examples/parquet_files.py +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing/examples/simple.zip +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing/filesystem.py +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing/indexing.py +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing/io_helpers.py +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing/io_parquet_helpers.py +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing/io_pyarrow_helpers.py +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing/merging.py +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing/proxies.py +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing/unique_fields.py +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing/utils.py +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing.egg-info/SOURCES.txt +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing.egg-info/dependency_links.txt +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing.egg-info/requires.txt +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/src/bw_processing.egg-info/top_level.txt +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/tests/test_array_creation.py +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/tests/test_datapackage.py +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/tests/test_filesystem.py +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/tests/test_filtered_datapackage.py +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/tests/test_indexing.py +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/tests/test_integration.py +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/tests/test_interfaces.py +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/tests/test_io_parquet_helpers.py +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/tests/test_io_pyarrow_helpers.py +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/tests/test_loading.py +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/tests/test_merging.py +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/tests/test_proxies.py +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/tests/test_unique_fields.py +0 -0
- {bw_processing-1.1 → bw_processing-1.1.1}/tests/test_utils.py +0 -0
|
@@ -2,6 +2,12 @@ import dataclasses
|
|
|
2
2
|
import math
|
|
3
3
|
from enum import Enum
|
|
4
4
|
|
|
5
|
+
try:
|
|
6
|
+
from stats_arrays import NoUncertainty, UndefinedUncertainty
|
|
7
|
+
_NO_UNCERTAINTY_IDS = (UndefinedUncertainty.id, NoUncertainty.id)
|
|
8
|
+
except ImportError:
|
|
9
|
+
_NO_UNCERTAINTY_IDS = (0, 1)
|
|
10
|
+
|
|
5
11
|
|
|
6
12
|
class MatrixName(str, Enum):
|
|
7
13
|
"""Standard matrix names used in Brightway.
|
|
@@ -63,6 +69,16 @@ class MatrixEntry:
|
|
|
63
69
|
maximum: float = math.nan
|
|
64
70
|
negative: bool = False
|
|
65
71
|
|
|
72
|
+
def __post_init__(self):
|
|
73
|
+
if self.uncertainty_type in _NO_UNCERTAINTY_IDS:
|
|
74
|
+
if math.isnan(self.loc):
|
|
75
|
+
object.__setattr__(self, "loc", self.amount)
|
|
76
|
+
elif self.loc != self.amount:
|
|
77
|
+
raise ValueError(
|
|
78
|
+
f"uncertainty_type {self.uncertainty_type} requires loc == amount, "
|
|
79
|
+
f"got loc={self.loc} but amount={self.amount}"
|
|
80
|
+
)
|
|
81
|
+
|
|
66
82
|
def as_dict(self) -> dict:
|
|
67
83
|
return dataclasses.asdict(self)
|
|
68
84
|
|
|
@@ -42,12 +42,32 @@ class TestMatrixEntry:
|
|
|
42
42
|
assert e.flip is False
|
|
43
43
|
assert e.uncertainty_type == 0
|
|
44
44
|
assert e.negative is False
|
|
45
|
-
assert
|
|
45
|
+
assert e.loc == pytest.approx(3.0)
|
|
46
46
|
assert math.isnan(e.scale)
|
|
47
47
|
assert math.isnan(e.shape)
|
|
48
48
|
assert math.isnan(e.minimum)
|
|
49
49
|
assert math.isnan(e.maximum)
|
|
50
50
|
|
|
51
|
+
def test_loc_set_to_amount_for_no_uncertainty(self):
|
|
52
|
+
e = MatrixEntry(row=1, col=2, amount=5.0)
|
|
53
|
+
assert e.loc == pytest.approx(5.0)
|
|
54
|
+
|
|
55
|
+
def test_explicit_loc_matching_amount_accepted(self):
|
|
56
|
+
e = MatrixEntry(row=1, col=2, amount=5.0, uncertainty_type=0, loc=5.0)
|
|
57
|
+
assert e.loc == pytest.approx(5.0)
|
|
58
|
+
|
|
59
|
+
def test_loc_mismatch_raises_for_uncertainty_type_0(self):
|
|
60
|
+
with pytest.raises(ValueError, match="loc == amount"):
|
|
61
|
+
MatrixEntry(row=1, col=2, amount=5.0, uncertainty_type=0, loc=9.9)
|
|
62
|
+
|
|
63
|
+
def test_loc_mismatch_raises_for_uncertainty_type_1(self):
|
|
64
|
+
with pytest.raises(ValueError, match="loc == amount"):
|
|
65
|
+
MatrixEntry(row=1, col=2, amount=5.0, uncertainty_type=1, loc=9.9)
|
|
66
|
+
|
|
67
|
+
def test_loc_not_set_when_uncertainty_type_nonzero(self):
|
|
68
|
+
e = MatrixEntry(row=1, col=2, amount=5.0, uncertainty_type=2)
|
|
69
|
+
assert math.isnan(e.loc)
|
|
70
|
+
|
|
51
71
|
def test_frozen(self):
|
|
52
72
|
e = MatrixEntry(row=1, col=2, amount=3.0)
|
|
53
73
|
with pytest.raises(Exception):
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|