Skip to content

Commit

Permalink
Fix iterable regression in concat introduced by #598 (#633)
Browse files Browse the repository at this point in the history
  • Loading branch information
coroa authored Feb 23, 2022
1 parent a223129 commit 38897ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions pyam/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2750,6 +2750,7 @@ def concat(objs, ignore_meta_conflict=False, **kwargs):
if not islistable(objs) or isinstance(objs, pd.DataFrame):
raise TypeError(f"'{objs.__class__.__name__}' object is not iterable")

objs = list(objs)
if len(objs) < 1:
raise ValueError("No objects to concatenate")

Expand Down
12 changes: 8 additions & 4 deletions tests/test_feature_append_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def test_append_incompatible_col_raises(test_df_year, test_pd_df, inplace):


@pytest.mark.parametrize("reverse", (False, True))
def test_concat(test_df, reverse):
@pytest.mark.parametrize("iterable", (False, True))
def test_concat(test_df, reverse, iterable):
other = test_df.filter(scenario="scen_b").rename({"scenario": {"scen_b": "scen_c"}})

test_df.set_meta([0, 1], name="col1")
Expand All @@ -83,10 +84,13 @@ def test_concat(test_df, reverse):
other.set_meta(2, name="col1")
other.set_meta("x", name="col3")

dfs = [test_df, other]
if reverse:
result = concat([other, test_df])
else:
result = concat([test_df, other])
dfs = list(reversed(dfs))
if iterable:
dfs = iter(dfs)

result = concat(dfs)

# check that the original object is not updated
assert test_df.scenario == ["scen_a", "scen_b"]
Expand Down

0 comments on commit 38897ff

Please sign in to comment.