Repository: IAMconsortium/pyam
Pull request #633 (2022-02-23 18:51:02)

Fix iterable regression in concat introduced by #598
Second take of #512 .

# Please confirm that this PR has done the following:

- [x] Tests Added
- [ ] ~Documentation Added~
- [ ] ~Name of contributors Added to AUTHORS.rst~
- [ ] ~Description in RELEASE_NOTES.md Added~


codecov[bot]: # [Codecov](https://codecov.io/gh/IAMconsortium/pyam/pull/633?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=IAMconsortium) Report
> Merging [#633](https://codecov.io/gh/IAMconsortium/pyam/pull/633?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=IAMconsortium) (6ef70a3) into [main](https://codecov.io/gh/IAMconsortium/pyam/commit/a223129071a7f6e6c7f5d1e14555a9e53b13eb67?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=IAMconsortium) (a223129) will **increase** coverage by `0.0%`.
> The diff coverage is `100.0%`.

[![Impacted file tree graph](https://codecov.io/gh/IAMconsortium/pyam/pull/633/graphs/tree.svg?width=650&height=150&src=pr&token=ThxWlNkonJ&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=IAMconsortium)](https://codecov.io/gh/IAMconsortium/pyam/pull/633?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=IAMconsortium)

```diff
@@          Coverage Diff          @@
##            main    #633   +/-   ##
=====================================
  Coverage   94.6%   94.6%           
=====================================
  Files         57      57           
  Lines       5646    5651    +5     
=====================================
+ Hits        5342    5347    +5     
  Misses       304     304           
```


| [Impacted Files](https://codecov.io/gh/IAMconsortium/pyam/pull/633?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=IAMconsortium) | Coverage Δ | |
|---|---|---|
| [pyam/core.py](https://codecov.io/gh/IAMconsortium/pyam/pull/633/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=IAMconsortium#diff-cHlhbS9jb3JlLnB5) | `94.9% <100.0%> (+<0.1%)` | :arrow_up: |
| [tests/test\_feature\_append\_concat.py](https://codecov.io/gh/IAMconsortium/pyam/pull/633/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=IAMconsortium#diff-dGVzdHMvdGVzdF9mZWF0dXJlX2FwcGVuZF9jb25jYXQucHk=) | `100.0% <100.0%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/IAMconsortium/pyam/pull/633?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=IAMconsortium).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=IAMconsortium)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/IAMconsortium/pyam/pull/633?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=IAMconsortium). Last update [a223129...6ef70a3](https://codecov.io/gh/IAMconsortium/pyam/pull/633?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=IAMconsortium). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=IAMconsortium).


Patch:
diff --git a/pyam/core.py b/pyam/core.py
index d23ca18..9541a81 100755
--- a/pyam/core.py
+++ b/pyam/core.py
@@ -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")
 


Test patch:
diff --git a/tests/test_feature_append_concat.py b/tests/test_feature_append_concat.py
index 69bb8c6..0e030ec 100644
--- a/tests/test_feature_append_concat.py
+++ b/tests/test_feature_append_concat.py
@@ -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")
@@ -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"]