Skip to content

Commit

Permalink
made factor column optional
Browse files Browse the repository at this point in the history
  • Loading branch information
konstantinstadler committed Jul 15, 2024
1 parent 981fd68 commit 00b36d9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pymrio/tools/ioutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,8 @@ def convert(df_orig, df_map, agg_func="sum", drop_not_bridged=True):
stressor ... original index name
compartment ... original index name
factor ... the factor for multiplication/characterization
If no factor is given, the factor is assumed to be 1.
This can be used, to simplify renaming/aggregation mappings.
impact__stressor ... the new index name,
replacing the previous index name "stressor".
Thus here "stressor" will be renamed to "impact", and the row index
Expand Down Expand Up @@ -1094,7 +1096,10 @@ def convert(df_orig, df_map, agg_func="sum", drop_not_bridged=True):
# the loop for getting all (potential regex) matches and multiplication
for row in df_cur_map.iterrows():
matched_entries = index_fullmatch(df_ix=df_orig, **row[1].to_dict())
mul_entries = matched_entries * row[1].factor
try:
mul_entries = matched_entries * row[1].factor
except AttributeError:
mul_entries = matched_entries
collector.append(mul_entries)

df_collected = pd.concat(collector, axis=0)
Expand Down
18 changes: 18 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,24 @@ def test_convert_rename():
)



# without factor should give the same result
rename_bridge_simple_wo_factor = pd.DataFrame(
columns=["em_type", "stressor__em_type"],
data=[
["em1", "emission-1"],
["em2", "emission2"],
["emA", "emission A"],
],
)

char_res_keep_comp_wo_factor = convert(to_char, rename_bridge_simple_wo_factor, drop_not_bridged=False)

pdt.assert_frame_equal(
char_res_keep_comp_wo_factor,
char_res_keep_comp)


def test_convert_characterize():
"""Testing the characterization of one table"""

Expand Down

0 comments on commit 00b36d9

Please sign in to comment.