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

Filter strict - only return data which matches exact combination of all arguments #740

Open
willu47 opened this issue May 3, 2023 · 3 comments

Comments

@willu47
Copy link

willu47 commented May 3, 2023

I'm dealing with some messy data, including models that have missing regions, variables and years.

If I filter on a sub-set of regions, I'm returned all the data which matches at least one of those regions (and the same for the other dimensions).

However, I only want to return the model, scenario and variable rows which match ALL the regions I pass in.

One idea is to add a strict=False flag to the .filter() method. If strict == True, then only data which matches all the arguments is returned for each model-scenario-variable group.

@willu47
Copy link
Author

willu47 commented May 3, 2023

The .require_data() method returns a pandas.DataFrame of model-scenario pairs which meet the criteria given. This could be used internally to return only data which meets all the criteria.

@danielhuppmann
Copy link
Member

If I understand you correctly, you want to have the data only for those model-scenario combinations where data for all regions is present, right?

Maybe the following can be helpful:

_df = df.filter(variable=[<list of variables>]

for r in [<list of regions>]:
    _df.require_data(region=r, exclude_on_fail=True)

_df.filter(exclude=False, inplace=True)

The exclude_on_fail-flag (available in all validation methods) sets the meta-indicator exclude to True for all scenarios that fail the validation. You can iterate the require_data() method and then remove all scenarios that failed at least one region-requirement.

@danielhuppmann
Copy link
Member

But of course, having a strict-filter option could be useful, but the devil is in the details of the implementation, I guess...

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

No branches or pull requests

2 participants