Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a typo in a log message and extend a docstring #235

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions pyam/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,11 @@ def require_variable(self, variable, unit=None, year=None,
return pd.DataFrame(index=idx).reset_index()

def validate(self, criteria={}, exclude_on_fail=False):
"""Validate scenarios using criteria on timeseries values
"""Validate scenarios using criteria on timeseries values. Returns all
lumbric marked this conversation as resolved.
Show resolved Hide resolved
scenarios which do not match the criteria and prints a log message or
returns None, if all scenarios match the criteria.
lumbric marked this conversation as resolved.
Show resolved Hide resolved

When called with `exclude_on_fail=True`, the object will be modified.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great addition, but let’s be more specific than “modified”: say “all scenarios not satisfying the criteria will be marked as exclude=True

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm yes, "modified" is not very specific. Modification of input objects can be dangerous in Python if users of the function are not aware of the behavior. Therefore when reading the word "modified" in the docstring, I'm warned as user, while in "marked as exclude=True" I have to think a bit more what that means. I've tried to incorporate both thoughts into the next commit for the function. I think for the method it is less important to emphasize this, letting the method modify the object is more conventional in Python, I guess.


Parameters
----------
Expand All @@ -532,7 +536,7 @@ def validate(self, criteria={}, exclude_on_fail=False):
df = _apply_criteria(self.data, criteria, in_range=False)

if not df.empty:
msg = '{} of {} data points to not satisfy the criteria'
msg = '{} of {} data points do not satisfy the criteria'
logger().info(msg.format(len(df), len(self.data)))

if exclude_on_fail and len(df) > 0:
Expand Down Expand Up @@ -1398,7 +1402,12 @@ def _make_index(df, cols=META_IDX):


def validate(df, criteria={}, exclude_on_fail=False, **kwargs):
"""Validate scenarios using criteria on timeseries values
"""Validate scenarios using criteria on timeseries values. Returns all
lumbric marked this conversation as resolved.
Show resolved Hide resolved
scenarios which do not match the criteria and prints a log message or
returns None, if all scenarios match the criteria.
lumbric marked this conversation as resolved.
Show resolved Hide resolved

When called with `exclude_on_fail=True`, the input object `df` will be
lumbric marked this conversation as resolved.
Show resolved Hide resolved
modified.

Parameters
----------
Expand Down