matrix-utils 0.7.0__tar.gz → 0.7.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.
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/CHANGELOG.md +4 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/PKG-INFO +1 -1
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/matrix_utils/__init__.py +1 -1
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/matrix_utils/array_mapper.py +2 -2
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/matrix_utils.egg-info/PKG-INFO +1 -1
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/array_mapper.py +36 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/.gitignore +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/.pre-commit-config.yaml +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/CODE_OF_CONDUCT.md +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/LICENSE +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/MANIFEST.in +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/README.md +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/binder/Brightway 2.5 demonstration.ipynb +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/binder/environment.yml +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/Brightway 2.5 - Linking with IAMs.ipynb +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/Brightway 2.5 demonstration.ipynb +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/Graph traversal with modification.ipynb +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/Indexing speed tests.ipynb +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/Interfaces which produce results for multiple matrices.ipynb +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/Mapping speed tests.ipynb +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/Multifunctionality with Brightway 2.5.ipynb +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/Real-time modification of hybrid databases.ipynb +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/Supply chain modification.ipynb +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/Untitled.ipynb +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/profiling/bw2.prof +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/profiling/bw2.svg +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/profiling/bw25.prof +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/profiling/bw25.svg +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/profiling/bw25_profile.txt +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/profiling/bw25_profiling.py +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/profiling/bw2_profile.txt +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/profiling/bw2_profiling.py +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/profiling/profiling-versus-bw2.py +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/speed_test_unique_indices.py +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/speed_tests.py +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/docs/Makefile +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/docs/conf.py +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/docs/index.rst +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/docs/loading.rst +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/docs/make.bat +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/docs/saving.rst +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/docs/utilities.rst +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/matrix_utils/aggregation.py +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/matrix_utils/errors.py +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/matrix_utils/indexers.py +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/matrix_utils/mapped_matrix.py +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/matrix_utils/mapped_matrix_dict.py +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/matrix_utils/resource_group.py +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/matrix_utils/utils.py +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/matrix_utils.egg-info/SOURCES.txt +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/matrix_utils.egg-info/dependency_links.txt +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/matrix_utils.egg-info/requires.txt +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/matrix_utils.egg-info/top_level.txt +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/pyproject.toml +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/setup.cfg +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/fixtures/__init__.py +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/fixtures/a-first.zip +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/fixtures/b-second.zip +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/fixtures/basic.py +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/fixtures/create_static_fixtures.py +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/fixtures/sa-1.zip +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/fixtures/sa-2.zip +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/indexers.py +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/integration.py +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/interfaces.py +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/mapped_matrix.py +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/masking.py +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/monte_carlo.py +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/ordering.py +0 -0
- {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/utils.py +0 -0
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
### [0.7.1] - 2026-03-20
|
|
4
|
+
|
|
5
|
+
* Fix all elements being masked return sparse matrix instead of array when indexing
|
|
6
|
+
|
|
3
7
|
### [0.7.0] - 2026-02-27
|
|
4
8
|
|
|
5
9
|
* Merge [#33](https://github.com/brightway-lca/matrix_utils/pull/33): Speed up large-index mapping by avoiding repeated unique and using fast integer dedupicator. Thanks @romainsacchi!
|
|
@@ -26,8 +26,6 @@ class ArrayMapper:
|
|
|
26
26
|
""" # NOQA: E501
|
|
27
27
|
|
|
28
28
|
def __init__(self, *, array: np.ndarray, sparse_cutoff: int = 50000, empty_ok: bool = False):
|
|
29
|
-
|
|
30
|
-
|
|
31
29
|
self._check_input_array(array)
|
|
32
30
|
|
|
33
31
|
# `np.unique` can be very slow on large, unsorted integer arrays.
|
|
@@ -86,6 +84,8 @@ class ArrayMapper:
|
|
|
86
84
|
|
|
87
85
|
result = np.zeros_like(array) - 1
|
|
88
86
|
mask = array <= self.max_value
|
|
87
|
+
if not mask.any():
|
|
88
|
+
return result
|
|
89
89
|
# https://numpy.org/doc/stable/reference/generated/numpy.matrix.A1.html
|
|
90
90
|
result[mask] = np.asarray(self.matrix[array[mask], np.zeros_like(array[mask])]).ravel() - 1
|
|
91
91
|
return result
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import numpy as np
|
|
2
2
|
import pytest
|
|
3
|
+
from scipy import sparse
|
|
3
4
|
|
|
4
5
|
import matrix_utils.array_mapper as array_mapper_module
|
|
5
6
|
from matrix_utils.array_mapper import ArrayMapper
|
|
@@ -92,6 +93,41 @@ def test_reverse_dict():
|
|
|
92
93
|
assert am.reverse_dict() == {0: 10, 1: 20, 2: 30}
|
|
93
94
|
|
|
94
95
|
|
|
96
|
+
def test_csc_empty_fancy_index_returns_sparse():
|
|
97
|
+
"""Document scipy behaviour: indexing a CSC matrix with two empty arrays returns
|
|
98
|
+
a sparse matrix of shape (1, 0), NOT an empty dense array.
|
|
99
|
+
|
|
100
|
+
This is the root cause of the bug fixed in ``map_array``: if this behaviour
|
|
101
|
+
changes in a future scipy release the guard ``if not mask.any()`` may no
|
|
102
|
+
longer be necessary, but removing it would still be safe.
|
|
103
|
+
"""
|
|
104
|
+
m = sparse.coo_matrix(([1], ([2], [0])), shape=(5, 1)).tocsc()
|
|
105
|
+
empty = np.array([], dtype=np.intp)
|
|
106
|
+
result = m[empty, empty]
|
|
107
|
+
assert sparse.issparse(result), (
|
|
108
|
+
f"Expected a sparse matrix but got {type(result)}. "
|
|
109
|
+
"scipy may have changed its fancy-indexing behaviour for CSC matrices — "
|
|
110
|
+
"re-evaluate whether the `if not mask.any()` guard in map_array is still needed."
|
|
111
|
+
)
|
|
112
|
+
assert result.shape == (1, 0), f"Expected shape (1, 0) but got {result.shape}."
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def test_all_values_exceed_max_value():
|
|
116
|
+
# Regression: when every lookup value exceeds max_value the mask is all-False,
|
|
117
|
+
# which causes csc_matrix[[], []] to return a (1, 0) sparse matrix whose
|
|
118
|
+
# np.asarray().ravel() has shape (1,) instead of (0,) — corrupting the result.
|
|
119
|
+
am = ArrayMapper(array=np.array([1, 2, 3]))
|
|
120
|
+
result = am.map_array(np.array([100, 200, 300]))
|
|
121
|
+
assert np.array_equal(result, [-1, -1, -1])
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def test_mixed_in_range_and_out_of_range():
|
|
125
|
+
# Some values in range, some beyond max_value — make sure both are handled.
|
|
126
|
+
am = ArrayMapper(array=np.array([1, 3, 5]))
|
|
127
|
+
result = am.map_array(np.array([1, 99, 3, 88, 5]))
|
|
128
|
+
assert np.array_equal(result, [0, -1, 1, -1, 2])
|
|
129
|
+
|
|
130
|
+
|
|
95
131
|
def test_large_integer_array_pandas_fallback(monkeypatch):
|
|
96
132
|
# Trigger the large integer optimization branch and force fallback
|
|
97
133
|
inpt = np.tile(np.array([5, 2, 7, 2, 5], dtype=np.int64), 25_000)
|
|
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.7.0 → matrix_utils-0.7.1}/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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|