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.
Files changed (70) hide show
  1. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/CHANGELOG.md +4 -0
  2. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/PKG-INFO +1 -1
  3. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/matrix_utils/__init__.py +1 -1
  4. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/matrix_utils/array_mapper.py +2 -2
  5. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/matrix_utils.egg-info/PKG-INFO +1 -1
  6. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/array_mapper.py +36 -0
  7. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/.gitignore +0 -0
  8. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/.pre-commit-config.yaml +0 -0
  9. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/CODE_OF_CONDUCT.md +0 -0
  10. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/LICENSE +0 -0
  11. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/MANIFEST.in +0 -0
  12. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/README.md +0 -0
  13. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/binder/Brightway 2.5 demonstration.ipynb +0 -0
  14. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/binder/environment.yml +0 -0
  15. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/Brightway 2.5 - Linking with IAMs.ipynb +0 -0
  16. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/Brightway 2.5 demonstration.ipynb +0 -0
  17. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/Graph traversal with modification.ipynb +0 -0
  18. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/Indexing speed tests.ipynb +0 -0
  19. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/Interfaces which produce results for multiple matrices.ipynb +0 -0
  20. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/Mapping speed tests.ipynb +0 -0
  21. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/Multifunctionality with Brightway 2.5.ipynb +0 -0
  22. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/Real-time modification of hybrid databases.ipynb +0 -0
  23. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/Supply chain modification.ipynb +0 -0
  24. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/Untitled.ipynb +0 -0
  25. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/profiling/bw2.prof +0 -0
  26. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/profiling/bw2.svg +0 -0
  27. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/profiling/bw25.prof +0 -0
  28. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/profiling/bw25.svg +0 -0
  29. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/profiling/bw25_profile.txt +0 -0
  30. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/profiling/bw25_profiling.py +0 -0
  31. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/profiling/bw2_profile.txt +0 -0
  32. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/profiling/bw2_profiling.py +0 -0
  33. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/profiling/profiling-versus-bw2.py +0 -0
  34. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/speed_test_unique_indices.py +0 -0
  35. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/dev/speed_tests.py +0 -0
  36. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/docs/Makefile +0 -0
  37. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/docs/conf.py +0 -0
  38. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/docs/index.rst +0 -0
  39. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/docs/loading.rst +0 -0
  40. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/docs/make.bat +0 -0
  41. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/docs/saving.rst +0 -0
  42. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/docs/utilities.rst +0 -0
  43. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/matrix_utils/aggregation.py +0 -0
  44. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/matrix_utils/errors.py +0 -0
  45. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/matrix_utils/indexers.py +0 -0
  46. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/matrix_utils/mapped_matrix.py +0 -0
  47. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/matrix_utils/mapped_matrix_dict.py +0 -0
  48. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/matrix_utils/resource_group.py +0 -0
  49. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/matrix_utils/utils.py +0 -0
  50. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/matrix_utils.egg-info/SOURCES.txt +0 -0
  51. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/matrix_utils.egg-info/dependency_links.txt +0 -0
  52. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/matrix_utils.egg-info/requires.txt +0 -0
  53. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/matrix_utils.egg-info/top_level.txt +0 -0
  54. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/pyproject.toml +0 -0
  55. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/setup.cfg +0 -0
  56. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/fixtures/__init__.py +0 -0
  57. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/fixtures/a-first.zip +0 -0
  58. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/fixtures/b-second.zip +0 -0
  59. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/fixtures/basic.py +0 -0
  60. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/fixtures/create_static_fixtures.py +0 -0
  61. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/fixtures/sa-1.zip +0 -0
  62. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/fixtures/sa-2.zip +0 -0
  63. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/indexers.py +0 -0
  64. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/integration.py +0 -0
  65. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/interfaces.py +0 -0
  66. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/mapped_matrix.py +0 -0
  67. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/masking.py +0 -0
  68. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/monte_carlo.py +0 -0
  69. {matrix_utils-0.7.0 → matrix_utils-0.7.1}/tests/ordering.py +0 -0
  70. {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!
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: matrix_utils
3
- Version: 0.7.0
3
+ Version: 0.7.1
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>
@@ -11,7 +11,7 @@ __all__ = (
11
11
  "SparseMatrixDict",
12
12
  )
13
13
 
14
- __version__ = "0.7.0"
14
+ __version__ = "0.7.1"
15
15
 
16
16
  from matrix_utils.array_mapper import ArrayMapper
17
17
  from matrix_utils.indexers import CombinatorialIndexer, Proxy, RandomIndexer, SequentialIndexer
@@ -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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: matrix_utils
3
- Version: 0.7.0
3
+ Version: 0.7.1
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>
@@ -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