Skip to content
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
4 changes: 2 additions & 2 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
- [#944](https://github.com/IAMconsortium/pyam/pull/944) Refactor to a `format_n()` function for nice log messages
- [#943](https://github.com/IAMconsortium/pyam/pull/943) Improved handling for division by zero
- [#941](https://github.com/IAMconsortium/pyam/pull/941) Add a `compute.share()` method
- [#938](https://github.com/IAMconsortium/pyam/pull/938) Add a function to initialize an IamDataFrame from an *
*ixmp4.Run**
- [#938](https://github.com/IAMconsortium/pyam/pull/938) Add a function to initialize an IamDataFrame from an **ixmp4.Run**
- [#950](https://github.com/IAMconsortium/pyam/pull/950) Add a useful error message on empty query result from an **ixmp4.Platform**

# Release v3.2.0

Expand Down
24 changes: 15 additions & 9 deletions pyam/ixmp4.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,24 @@ def read_ixmp4(
meta_filters = dict(
run=dict(default_only=default_only, model=model, scenario=scenario)
)
iamc_filters = dict(
run=dict(default_only=default_only),
model=model,
scenario=scenario,
region=region,
variable=variable,
unit=unit,
year=year,
)
iamc_filters = dict(run=dict(default_only=default_only))
for key, value in (
("model", model),
("scenario", scenario),
("region", region),
("variable", variable),
("unit", unit),
("year", year),
):
if value is not None:
iamc_filters[key] = value

data = platform.iamc.tabulate(**iamc_filters)
meta = platform.meta.tabulate(**meta_filters)

if data.empty:
raise ValueError("No scenario data with filters " + str(iamc_filters))

# if default-only, simplify to standard IAMC index, add `version` as meta indicator
if default_only:
index = ["model", "scenario"]
Expand Down
5 changes: 5 additions & 0 deletions tests/test_ixmp4.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ def test_ixmp4_reserved_columns(test_platform, test_df_year, drop_meta):
assert_iamframe_equal(test_df_year, pyam.read_ixmp4(test_platform))


def test_ixmp4_empty_result(test_platform):
with pytest.raises(ValueError, match=r"No scenario data with filters \{.*'foo'\}"):
read_ixmp4(test_platform, variable="foo")


def test_ixmp4_read_run(test_platform, test_df):
"""Initialize an IamDataFrame from an ixmp4 run"""

Expand Down