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

Extend the validate() signature #804

Merged
merged 13 commits into from
Dec 12, 2023

Conversation

danielhuppmann
Copy link
Member

@danielhuppmann danielhuppmann commented Dec 11, 2023

Please confirm that this PR has done the following:

  • Tests Added
  • Documentation Added
  • Name of contributors Added to AUTHORS.rst
  • Description in RELEASE_NOTES.md Added

Description of PR

This PR extends the signature of the validate() method to take filter-arguments directly instead of using a (nested) dictionary, so

df.validate({"Primary Energy": {"up": x, year=y}})

can now be called as

df.validate(variable="Primary Energy", year=y, upper=x)

This allows to validate only a selection of the datapoints, e.g., filtered by region or model/scenario name. The signature can also more easily be called from a (to-be-implemented) processor in the nomenclature package.

The option to use nested dicts is marked as deprecated with release 3.0.

@danielhuppmann danielhuppmann self-assigned this Dec 11, 2023
Copy link

codecov bot commented Dec 11, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (d1cd1f7) 94.7% compared to head (a2fefa9) 94.7%.

Files Patch % Lines
pyam/validation.py 96.0% 1 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main    #804   +/-   ##
=====================================
  Coverage   94.7%   94.7%           
=====================================
  Files         62      62           
  Lines       6012    6058   +46     
=====================================
+ Hits        5696    5741   +45     
- Misses       316     317    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@phackstock phackstock left a comment

Choose a reason for hiding this comment

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

Some minor comments, but in principle already good to merge from my side.

pdt.assert_frame_equal(obs, test_df.data[5:6].reset_index(drop=True))
assert list(test_df.exclude) == [False, True]


def test_validate_multiple_criteria(test_df):
Copy link
Contributor

Choose a reason for hiding this comment

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

You could assert here in addition that the deprecation warning is issued.

"Use `upper`, `lower`, and filter-arguments instead.", "Argument `criteria`"
)
if upper or lower is not None and not kwargs.empty:
raise NotImplementedError(
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems that Codecov and I came to the same conclusion here :D

pyam/core.py Outdated Show resolved Hide resolved
pyam/core.py Outdated Show resolved Hide resolved
@danielhuppmann
Copy link
Member Author

Thanks @phackstock - implemented your suggestion for upper_bound and lower_bound, but I don't think that checking deprecation-warnings is worth the effort...

@danielhuppmann danielhuppmann merged commit ba3069e into IAMconsortium:main Dec 12, 2023
11 checks passed
@danielhuppmann danielhuppmann deleted the feature/validate branch December 12, 2023 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants