Skip to content

Commit c721cfc

Browse files
committed
Fix override of states in state expansion
1 parent 7364a6e commit c721cfc

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

CITATION.cff

Whitespace-only changes.

src/simdec/decomposition.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
def states_expansion(states: list[int], inputs: pd.DataFrame) -> list[list[str]]:
1616
"""Expand states list to fully represent all scenarios."""
1717
inputs = pd.DataFrame(inputs)
18-
for i, state in enumerate(states):
18+
expanded_states = []
19+
for state in states:
1920
if isinstance(state, int):
20-
states: list
2121
if state == 2:
22-
states[i] = ["low", "high"]
22+
expanded_states.append(["low", "high"])
2323
elif state == 3:
24-
states[i] = ["low", "medium", "high"]
24+
expanded_states.append(["low", "medium", "high"])
25+
else:
26+
expanded_states.append(state)
2527

2628
# categorical for a given variable
2729
cat_cols = inputs.select_dtypes(exclude=["number"])
@@ -34,9 +36,9 @@ def states_expansion(states: list[int], inputs: pd.DataFrame) -> list[list[str]]
3436

3537
for i, states_cat_ in zip(cat_cols_idx, states_cats_):
3638
n_unique = np.unique(inputs.iloc[:, i]).size
37-
states[i] = list(states_cat_) if n_unique < 5 else states[i]
39+
expanded_states[i] = list(states_cat_) if n_unique < 5 else expanded_states[i]
3840

39-
return states
41+
return expanded_states
4042

4143

4244
@dataclass

0 commit comments

Comments
 (0)