Skip to content

Commit

Permalink
add (and test) explicit warning message
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhuppmann committed Jun 16, 2020
1 parent e74d504 commit 9b4c904
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion pyam/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ class IamDataFrame(object):
"""
def __init__(self, data, **kwargs):
"""Initialize an instance of an IamDataFrame"""
if isinstance(data, IamDataFrame) and not kwargs:
if isinstance(data, IamDataFrame):
if kwargs:
msg = 'Invalid arguments `{}` for initializing an IamDataFrame'
raise ValueError(msg.format(kwargs))
for attr, value in data.__dict__.items():
setattr(self, attr, value)
else:
Expand Down
5 changes: 4 additions & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ def test_init_from_iamdf(test_df_year):

def test_init_from_iamdf_raises(test_df_year):
# casting an IamDataFrame instance again with extra args fails
pytest.raises(ValueError, IamDataFrame, test_df_year, model='foo')
args = dict(model='foo')
match = f'Invalid arguments `{args}` for initializing an IamDataFrame'
with pytest.raises(ValueError, match=match):
IamDataFrame(test_df_year, **args)


def test_init_df_with_float_cols_raises(test_pd_df):
Expand Down

0 comments on commit 9b4c904

Please sign in to comment.