From dbef92087c5be6d1988f8d106b51097696689d4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Dupuis?= Date: Tue, 19 Nov 2024 10:22:55 -0500 Subject: [PATCH 1/3] only local changes for base_kws_vars --- CHANGELOG.rst | 1 + xclim/sdba/adjustment.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 15dd45bfe..c2b931d9e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,6 +14,7 @@ Bug fixes ^^^^^^^^^ * Fixed pickling issue with ``xclim.sdba.Grouper`` and other classes for usage with `dask>=2024.11`. (:issue:`1992`, :pull:`1993`). * Fixed an issue with ``nimbus`` that was causing URL path components to be improperly joined. (:pull:`1997`). +* `base_kws_vars` in `MBCn` is now copied inside the `adjust` function so that in-place changes do not change the dict globally. Internal changes ^^^^^^^^^^^^^^^^ diff --git a/xclim/sdba/adjustment.py b/xclim/sdba/adjustment.py index 5c8506071..be1981d53 100644 --- a/xclim/sdba/adjustment.py +++ b/xclim/sdba/adjustment.py @@ -5,6 +5,7 @@ """ from __future__ import annotations +import copy from importlib.util import find_spec from inspect import signature from typing import Any @@ -1818,7 +1819,7 @@ def _adjust( period_dim=None, ): # set default values for non-specified parameters - base_kws_vars = base_kws_vars or {} + base_kws_vars = copy.deepcopy(base_kws_vars) or {} pts_dim = self.pts_dims[0] for v in sim[pts_dim].values: base_kws_vars.setdefault(v, {}) From 13965d913d794c8786f7cf4ca89211ec0aa2b932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Dupuis?= Date: Tue, 19 Nov 2024 10:26:02 -0500 Subject: [PATCH 2/3] add pull number --- CHANGELOG.rst | 2 +- xclim/sdba/adjustment.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c2b931d9e..aed32045a 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,7 +14,7 @@ Bug fixes ^^^^^^^^^ * Fixed pickling issue with ``xclim.sdba.Grouper`` and other classes for usage with `dask>=2024.11`. (:issue:`1992`, :pull:`1993`). * Fixed an issue with ``nimbus`` that was causing URL path components to be improperly joined. (:pull:`1997`). -* `base_kws_vars` in `MBCn` is now copied inside the `adjust` function so that in-place changes do not change the dict globally. +* `base_kws_vars` in `MBCn` is now copied inside the `adjust` function so that in-place changes do not change the dict globally. (:pull:`1999`). Internal changes ^^^^^^^^^^^^^^^^ diff --git a/xclim/sdba/adjustment.py b/xclim/sdba/adjustment.py index be1981d53..5a1c5db01 100644 --- a/xclim/sdba/adjustment.py +++ b/xclim/sdba/adjustment.py @@ -5,7 +5,7 @@ """ from __future__ import annotations -import copy +from copy import deepcopy from importlib.util import find_spec from inspect import signature from typing import Any @@ -1819,7 +1819,7 @@ def _adjust( period_dim=None, ): # set default values for non-specified parameters - base_kws_vars = copy.deepcopy(base_kws_vars) or {} + base_kws_vars = deepcopy(base_kws_vars) or {} pts_dim = self.pts_dims[0] for v in sim[pts_dim].values: base_kws_vars.setdefault(v, {}) From d31f51ec73e76b1999a47eeb651dbe29e98721ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Dupuis?= Date: Tue, 19 Nov 2024 10:27:26 -0500 Subject: [PATCH 3/3] check None first --- xclim/sdba/adjustment.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xclim/sdba/adjustment.py b/xclim/sdba/adjustment.py index 5a1c5db01..da5ab54fe 100644 --- a/xclim/sdba/adjustment.py +++ b/xclim/sdba/adjustment.py @@ -1819,7 +1819,7 @@ def _adjust( period_dim=None, ): # set default values for non-specified parameters - base_kws_vars = deepcopy(base_kws_vars) or {} + base_kws_vars = {} if base_kws_vars is None else deepcopy(base_kws_vars) pts_dim = self.pts_dims[0] for v in sim[pts_dim].values: base_kws_vars.setdefault(v, {})