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

Update error message for empty dataframe #107

Merged
merged 5 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 4 additions & 3 deletions nomenclature/processor/region.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,15 @@ def apply(self, df: IamDataFrame, dsd: DataStructureDefinition) -> IamDataFrame:

# If no mapping is defined the data frame is returned unchanged
if model not in self.mappings:
logger.info(f"No region aggregation mapping found for model {model}")
logger.info(f"No model mapping found for model {model}")
processed_dfs.append(model_df)

# Otherwise we first rename, then aggregate
else:
# before aggregating, check that all regions are valid
self.mappings[model].validate_regions(dsd)
logger.info(
f"Applying region aggregation for model {model} from file "
f"Applying region-processing for model {model} from file "
f"{self.mappings[model].file}"
)

Expand Down Expand Up @@ -408,7 +408,8 @@ def apply(self, df: IamDataFrame, dsd: DataStructureDefinition) -> IamDataFrame:

if not processed_dfs:
raise ValueError(
f"The region aggregation for model {model} resulted in an empty dataset"
f"The region-processing for model(s) {df.model} returned an empty "
"dataset"
)

return pyam.concat(processed_dfs)
Expand Down
4 changes: 4 additions & 0 deletions tests/data/region_processing/rename_only/model_b.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
model: model_b
native_regions:
- region_a: region_A
- region_B
4 changes: 2 additions & 2 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ def test_region_processing_empty_raises():
pd.DataFrame(
[
["model_a", "scen_a", "region_foo", "Primary Energy", "EJ/yr", 1, 2],
["model_b", "scen_a", "region_foo", "Primary Energy", "EJ/yr", 1, 2],
],
columns=IAMC_IDX + [2005, 2010],
)
)

with pytest.raises(ValueError, match="The region aggregation for model model_a"):
with pytest.raises(ValueError, match=("'model_a', 'model_b'.*empty dataset")):
process(
test_df,
DataStructureDefinition(TEST_DATA_DIR / "region_processing/dsd"),
Expand Down