Skip to content

Commit 01f7694

Browse files
committed
makes addition and subtraction work also for ivs of different index
1 parent 189488f commit 01f7694

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

CHANGELOG.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,20 @@ We have begun the process of modularizing the `shapiq` package by splitting it i
1212

1313
This restructuring aims to improve maintainability and development scalability. The core `shapiq` package will continue to receive the majority of updates and enhancements, and keeping it streamlined ensures better focus and usability. Meanwhile, separating games and benchmarking functionality allows these components to evolve more independently while maintaining compatibility through clearly defined dependencies.
1414

15-
### Removed Features
16-
- removes the ability to load `InteractionValues` from pickle files. This is now deprecated and will be removed in the next release. Use `InteractionValues.save(..., as_json=True)` to save interaction values as JSON files instead. [#413](https://github.com/mmschlk/shapiq/issues/413)
15+
### Maintenance and Development
16+
- refactored the `shapiq.Games` and `shapiq.InteractionValues` API by adding an interactions and game_values dictionary as the main data structure to store the interaction scores and game values. This allows for more efficient storage and retrieval of interaction values and game values, as well as easier manipulation of the data. [#419](https://github.com/mmschlk/shapiq/pull/419)
17+
- addition and subtraction of InteractionValues objects (via `shapiq.InteractionValues.__add__`) now also works for different indices, which will raise a warning and will return a new InteractionValues object with the index set of the first. [#422](https://github.com/mmschlk/shapiq/pull/422)
1718

1819
### Docs
19-
- added an example notebook for `InteractionValues`, highlighting *Initialisation*, *Modification*, *Visualization* and *Save and Loading*.
20+
- added an example notebook for `InteractionValues`, highlighting *Initialization*, *Modification*, *Visualization* and *Save and Loading*.
2021

2122
### Bugfixes
2223
- fixes a bug where RegressionFBII approximator was throwing an error when the index was `'BV'` or `'FBII'`.[#420](https://github.com/mmschlk/shapiq/pull/420)
2324

25+
### Removed Features
26+
- removes the ability to load `InteractionValues` from pickle files. This is now deprecated and will be removed in the next release. Use `InteractionValues.save(..., as_json=True)` to save interaction values as JSON files instead. [#413](https://github.com/mmschlk/shapiq/issues/413)
27+
28+
2429
## v1.3.1 (2025-07-11)
2530

2631
### New Features

src/shapiq/interaction_values.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,10 +487,10 @@ def __add__(self, other: InteractionValues | float) -> InteractionValues:
487487
if isinstance(other, InteractionValues):
488488
if self.index != other.index: # different indices
489489
msg = (
490-
f"Cannot add InteractionValues with different indices {self.index} and "
491-
f"{other.index}."
490+
f"The indices of the InteractionValues objects are different: "
491+
f"{self.index} != {other.index}. Addition might not be meaningful."
492492
)
493-
raise ValueError(msg)
493+
warn(msg, stacklevel=2)
494494
if (
495495
self.interaction_lookup != other.interaction_lookup
496496
or self.n_players != other.n_players

tests/shapiq/tests_unit/test_interaction_values.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,10 @@ def test_add():
191191
interaction_lookup=interaction_lookup,
192192
baseline_value=0.0,
193193
)
194-
with pytest.raises(ValueError):
195-
interaction_values_first + interaction_values_second
194+
with pytest.warns(match="The indices of the InteractionValues objects are different:"):
195+
result = interaction_values_first + interaction_values_second
196+
assert result.index == interaction_values_first.index
197+
assert result.index != interaction_values_second.index
196198

197199
# test adding InteractionValues with different interactions
198200
n_players_second = n + 1

uv.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)