Skip to content

Commit 07c08c4

Browse files
committed
Fix ruff formatting
1 parent 6ed821f commit 07c08c4

2 files changed

Lines changed: 17 additions & 20 deletions

File tree

src/dscim/menu/main_recipe.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -247,17 +247,17 @@ def __init__(
247247
self.logger = logging.getLogger(__name__)
248248

249249
if self.quantreg_quantiles is not None:
250-
assert len(self.quantreg_quantiles) == len(
251-
self.quantreg_weights
252-
), "Length of quantreg quantiles does not match length of weights."
250+
assert len(self.quantreg_quantiles) == len(self.quantreg_weights), (
251+
"Length of quantreg quantiles does not match length of weights."
252+
)
253253

254-
assert (
255-
self.discounting_type in self.DISCOUNT_TYPES
256-
), f"Discount type not implemented. Try one of {self.DISCOUNT_TYPES}."
254+
assert self.discounting_type in self.DISCOUNT_TYPES, (
255+
f"Discount type not implemented. Try one of {self.DISCOUNT_TYPES}."
256+
)
257257

258-
assert (
259-
self.formula in self.FORMULAS
260-
), f"Formula not implemented. Try one of {self.FORMULAS}."
258+
assert self.formula in self.FORMULAS, (
259+
f"Formula not implemented. Try one of {self.FORMULAS}."
260+
)
261261

262262
# Set stream of discounts to None if discounting_type is 'constant'
263263
# 'constant_model_collapsed' should be here except that we allow
@@ -488,10 +488,7 @@ def _aggregate_by_geography(
488488
return data # No aggregation needed
489489

490490
elif geography == "country":
491-
if (
492-
hasattr(self, "country_mapping")
493-
and self.country_mapping is not None
494-
):
491+
if hasattr(self, "country_mapping") and self.country_mapping is not None:
495492
return self._aggregate_to_country(data)
496493
else:
497494
raise ValueError(
@@ -530,9 +527,7 @@ def _aggregate_to_country(self, data: xr.DataArray) -> xr.DataArray:
530527
else "nopop"
531528
for _, row in self.country_mapping.iterrows()
532529
}
533-
territories = [
534-
mapping.get(str(r)[:3], "unknown") for r in data.region.values
535-
]
530+
territories = [mapping.get(str(r)[:3], "unknown") for r in data.region.values]
536531
return data.assign_coords({"region": territories}).groupby("region").sum()
537532

538533
def damages_dataset(self, geography: str = "globe") -> xr.Dataset:
@@ -579,9 +574,7 @@ def _filter_illegal_combinations_xr(self, ds: xr.Dataset) -> xr.Dataset:
579574
xr.Dataset
580575
Filtered dataset with illegal combinations set to NaN
581576
"""
582-
if "ssp" in ds.coords and any(
583-
ssp in ds.ssp.values for ssp in ["SSP1", "SSP5"]
584-
):
577+
if "ssp" in ds.coords and any(ssp in ds.ssp.values for ssp in ["SSP1", "SSP5"]):
585578
self.logger.info("Dropping illegal model combinations.")
586579
illegal = ((ds.ssp == "SSP1") & (ds.rcp == "rcp85")) | (
587580
(ds.ssp == "SSP5") & (ds.rcp == "rcp45")

tests/test_geography.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,11 @@ def test_xarray_path_matches_pandas_path_for_globe(self, menu_instance):
139139
assert "damages" in pandas_result.columns
140140
assert "damages" in xarray_result.columns
141141

142-
sort_cols = [c for c in ["year", "ssp", "model", "gcm", "rcp"] if c in pandas_result.columns]
142+
sort_cols = [
143+
c
144+
for c in ["year", "ssp", "model", "gcm", "rcp"]
145+
if c in pandas_result.columns
146+
]
143147
pandas_sorted = pandas_result.sort_values(sort_cols).reset_index(drop=True)
144148
xarray_sorted = xarray_result.sort_values(sort_cols).reset_index(drop=True)
145149

0 commit comments

Comments
 (0)