Skip to content

Commit 7aff4bf

Browse files
Rework various log and error messages
1 parent 01611d8 commit 7aff4bf

File tree

8 files changed

+14
-11
lines changed

8 files changed

+14
-11
lines changed

pyam/_debiasing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ def _compute_bias(df, name, method, axis):
66
count.name = name
77
df.meta = df.meta.join(count, on=axis, how="outer")
88
else:
9-
raise ValueError(f"Unknown method {method} for computing bias weights!")
9+
raise ValueError(f"Unknown method '{method}' for computing bias weights.")

pyam/_style.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def _get_standard_colors( # noqa: C901
2323
cmap = colormap
2424
colormap = plt.get_cmap(colormap)
2525
if colormap is None:
26-
raise ValueError(f"Colormap {cmap} is not recognized")
26+
raise ValueError(f"Colormap '{cmap}' is not recognized.")
2727
colors = [colormap(num) for num in np.linspace(0, 1, num=num_colors)]
2828
elif color is not None:
2929
if colormap is not None:

pyam/aggregation.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def _aggregate_recursive(df, variable, recursive):
6565

6666
# downselect to components of `variable`, initialize list for aggregated (new) data
6767
# keep variable at highest level if it exists
68-
_df = df.filter(variable=[variable, f"{variable}|*"])
68+
_df = df.filter(variable=[variable, variable + "|*"])
6969
data_list = []
7070

7171
# iterate over variables (bottom-up) and aggregate all components up to `variable`
@@ -86,8 +86,10 @@ def _aggregate_recursive(df, variable, recursive):
8686
if recursive != "skip-validate" and not _overlap.empty:
8787
conflict = _compare(_data_self, _data_agg[_overlap], "self", "aggregate")
8888
if not conflict.empty:
89-
msg = "Aggregated values are inconsistent with existing data:"
90-
raise ValueError(f"{msg}\n{conflict}")
89+
raise ValueError(
90+
"Aggregated values are inconsistent with existing data:\n"
91+
+ str(conflict)
92+
)
9193

9294
# append aggregated values that are not already in data
9395
_df.append(_data_agg[_new], inplace=True)

pyam/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ def _get_meta_index_levels(self, name):
372372
if name in self.meta.index.names:
373373
return get_index_levels(self.meta, name)
374374
# in case of non-standard meta.index.names
375-
raise KeyError(f"Index `{name}` does not exist!")
375+
raise KeyError("Index dimension not found: " + name)
376376

377377
@property
378378
def region(self):

pyam/iiasa.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def __init__(self, name=None, creds=None, auth_url=_AUTH_URL):
168168
self.connect(name)
169169

170170
if self.auth.user is not None:
171-
logger.info(f"You are connected as user `{self.auth.user}`")
171+
logger.info(f"You are connected as user '{self.auth.user}'")
172172
else:
173173
logger.info("You are connected as an anonymous user")
174174

pyam/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ def _intuit_column_groups(df, index, include_index=False): # noqa: C901
281281
missing_required_col = [c for c in REQUIRED_COLS if c not in existing_cols]
282282
if missing_required_col:
283283
raise ValueError(
284-
f"Missing required columns in timeseries data: {missing_required_col}"
284+
"Missing required columns in timeseries data: "
285+
", ".join.missing_required_col
285286
)
286287

287288
# check whether data in wide format (standard IAMC) or long format (`value` column)

tests/test_core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def test_init_df_with_custom_index(test_pd_df):
238238
# check that index attributes were set correctly and that df.model fails
239239
assert df.source == ["model_a"]
240240
assert df.version == [1, 2, 3]
241-
with pytest.raises(KeyError, match="Index `model` does not exist!"):
241+
with pytest.raises(KeyError, match="Index dimension not found: model"):
242242
df.model
243243

244244

@@ -264,7 +264,7 @@ def test_init_with_illegal_column(test_pd_df, illegal):
264264
test_pd_df[illegal] = "foo"
265265

266266
# check that initialising an instance with an illegal column name raises
267-
msg = f"Illegal columns for timeseries data: '{illegal}'"
267+
msg = f"Illegal columns for timeseries data: {illegal}"
268268
with pytest.raises(ValueError, match=msg):
269269
IamDataFrame(test_pd_df)
270270

tests/test_feature_debiasing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ def test_debiasing_count(test_pd_df, axis, exp):
2121

2222
def test_debiasing_unknown_method(test_df_year):
2323
"""Check computing bias weights counting the number of scenarios by scenario name"""
24-
msg = "Unknown method foo for computing bias weights!"
24+
msg = "Unknown method 'foo' for computing bias weights."
2525
with pytest.raises(ValueError, match=msg):
2626
test_df_year.compute.bias(method="foo", name="bias", axis="scenario")

0 commit comments

Comments
 (0)