diff --git a/docs/release-notes.md b/docs/release-notes.md index 1f1f48a0..0d4f1c5a 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -8,7 +8,8 @@ SPDX-License-Identifier: MIT ## Upcoming Version -* +* Deprecate the argument `extend_by_vres` of `pm.powerplants()` and the function `extend_by_VRE()`. Both will be removed in v0.11.0. Wind and solar power plants are already included from GEM and MASTR, and the option added them again from outdated OPSD data (2020). ([#232](https://github.com/PyPSA/powerplantmatching/issues/232)) + * Bugfix: `pm.powerplants(from_url=True)` now applies `extend_by_vres` like the other code paths, and the deprecated argument `extendby_kwargs` now raises a `FutureWarning` instead of a logging error. ## [v0.9.0](https://github.com/PyPSA/powerplantmatching/releases/tag/v0.9.0) (3rd October 2026) diff --git a/powerplantmatching/collection.py b/powerplantmatching/collection.py index a677ae52..99be0eb0 100644 --- a/powerplantmatching/collection.py +++ b/powerplantmatching/collection.py @@ -8,6 +8,7 @@ import logging import os +import warnings import pandas as pd from deprecation import deprecated @@ -143,8 +144,10 @@ def powerplants( Configuration input dictionary to be merged into the default configuration data extend_by_vres : Boolean, default False - Whether extend the dataset by variable renewable energy sources - given by powerplantmatching.data.OPSD_VRE() + Deprecated since v0.10.0 and will be removed in v0.11.0. Wind and + solar power plants are already included from GEM and MASTR. This + option adds them again from the outdated + powerplantmatching.data.OPSD_VRE() and counts them twice. extendby_kwargs : Dict, Dict of keyword arguments passed to powerplantmatchting. heuristics.extend_by_non_matched @@ -164,6 +167,15 @@ def powerplants( """ from . import latest_release + if extend_by_vres: + warnings.warn( + "`extend_by_vres` is deprecated and will be removed in v0.11.0. Wind " + "and solar power plants are already included from GEM and MASTR. " + "This option adds them again from outdated OPSD data (2020).", + FutureWarning, + stacklevel=2, + ) + if config is None: if config_update is None: config = get_config() @@ -180,9 +192,10 @@ def powerplants( msg = "The following arguments were deprecated and are being ignored: " logger.warning(msg + f"{used_deprecated_args}") if extendby_kwargs: - logger.warning( - DeprecationWarning, - "`extendby_kwargs` is deprecated in the favor of extend_by_kwargs", + warnings.warn( + "`extendby_kwargs` is deprecated in favor of `extend_by_kwargs`", + FutureWarning, + stacklevel=2, ) extend_by_kwargs.update(extendby_kwargs) @@ -206,6 +219,10 @@ def powerplants( ) logger.info(f"Store data at {fn}") df.to_csv(fn) + if extend_by_vres: + return df.pipe( + extend_by_VRE, config=config, base_year=config["opsd_vres_base_year"] + ) return df if not update and os.path.exists(fn): diff --git a/powerplantmatching/heuristics.py b/powerplantmatching/heuristics.py index d48b3794..1b621415 100644 --- a/powerplantmatching/heuristics.py +++ b/powerplantmatching/heuristics.py @@ -189,6 +189,11 @@ def fill_missing_duration(df): return df +@deprecated( + deprecated_in="0.10.0", + removed_in="0.11.0", + details="Wind and solar power plants are already included from GEM and MASTR.", +) def extend_by_VRE(df, config=None, base_year=2017, prune_beyond=True): """ Extends a given reduced dataframe by externally given VREs. diff --git a/test/test_data.py b/test/test_data.py index d3614371..9c1294da 100755 --- a/test/test_data.py +++ b/test/test_data.py @@ -2,10 +2,13 @@ # # SPDX-License-Identifier: MIT +import pandas as pd import pytest +from deprecation import DeprecatedWarning import powerplantmatching as pm from powerplantmatching import data +from powerplantmatching.core import _data_out, package_config config = pm.get_config() sources = [s if isinstance(s, str) else list(s)[0] for s in config["matching_sources"]] @@ -64,3 +67,32 @@ def test_reduced_retrieval(): config["matching_sources"] = ["GEO", "GPD"] config["fully_included_sources"] = [] pm.powerplants(reduced=False, config=config) + + +@pytest.fixture +def cached_config(tmp_path, monkeypatch): + monkeypatch.setitem(package_config, "data_dir", tmp_path) + config = pm.get_config() + columns = config["target_columns"] + fn = _data_out("matched_data_red.csv", config) + plant = {"Name": ["A"], "Fueltype": ["Hydro"], "EIC": ["{}"], "projectID": ["{}"]} + pd.DataFrame(plant, columns=columns).to_csv(fn) + config["matched_data_url"] = fn + vre = pd.DataFrame({"Name": ["B"], "Fueltype": ["Solar"]}, columns=columns) + monkeypatch.setattr(data, "OPSD_VRE", lambda config: vre) + return config + + +@pytest.mark.parametrize("from_url", [False, True]) +def test_extend_by_vres_deprecated(cached_config, from_url): + with pytest.warns(FutureWarning, match="extend_by_vres"): + with pytest.warns(DeprecatedWarning, match="extend_by_VRE"): + df = pm.powerplants( + config=cached_config, from_url=from_url, extend_by_vres=True + ) + assert df.Fueltype.tolist() == ["Hydro", "Solar"] + + +def test_extendby_kwargs_deprecated(cached_config): + with pytest.warns(FutureWarning, match="extendby_kwargs"): + pm.powerplants(config=cached_config, extendby_kwargs={"query": None})