From d7ec02474d63b5324bbca8c93a8f1640778e1244 Mon Sep 17 00:00:00 2001 From: Pascal Bourgault Date: Mon, 11 Nov 2024 17:21:10 -0500 Subject: [PATCH 1/2] Fix wrong unpickling with dask 2024.11 --- CHANGELOG.rst | 6 +++++- environment.yml | 2 +- pyproject.toml | 2 +- xclim/sdba/base.py | 18 +++++++++--------- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0f2da06ec..e1fca65e7 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,12 +4,16 @@ Changelog v0.54.0 (unreleased) -------------------- -Contributors to this version: Trevor James Smith (:user:`Zeitsperre`), +Contributors to this version: Trevor James Smith (:user:`Zeitsperre`), Pascal Bourgault (:user:`aulemahal`). Breaking changes ---------------- * The minimum required version of `dask` has been increased to `2024.8.1`. `dask` versions at or above `2024.11` are not yet supported. (:issue:`1992`, :pull:`1991`). +Bug fixes +^^^^^^^^^ +* Fixes ``xclim.sdba.Grouper`` and other classes for usage with dask 2024.11 (:issue:`1992`, :pull:`1993`). + v0.53.2 (2024-10-31) -------------------- Contributors to this version: Éric Dupuis (:user:`coxipi`), Pascal Bourgault (:user:`aulemahal`), Trevor James Smith (:user:`Zeitsperre`). diff --git a/environment.yml b/environment.yml index 7a5f08ad9..88f13bce9 100644 --- a/environment.yml +++ b/environment.yml @@ -9,7 +9,7 @@ dependencies: - cf_xarray >=0.9.3 - cftime >=1.4.1 - click >=8.1 - - dask >=2024.8.1,<2024.11.0 + - dask >=2024.8.1 - filelock >=3.14.0 - jsonpickle >=3.1.0 - numba >=0.54.1 diff --git a/pyproject.toml b/pyproject.toml index 5ab0d9c3e..c6bb2592a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,7 +39,7 @@ dependencies = [ "cf-xarray >=0.9.3", # cf-xarray is differently named on conda-forge "cftime >=1.4.1", "click >=8.1", - "dask[array] >=2024.8.1,<2024.11.0", + "dask[array] >=2024.8.1", "filelock >=3.14.0", "jsonpickle >=3.1.0", "numba >=0.54.1", diff --git a/xclim/sdba/base.py b/xclim/sdba/base.py index 5036058ef..03ec7d091 100644 --- a/xclim/sdba/base.py +++ b/xclim/sdba/base.py @@ -5,6 +5,7 @@ from __future__ import annotations +from collections import UserDict from collections.abc import Callable, Sequence from inspect import _empty, signature # noqa @@ -20,7 +21,7 @@ # ## Base class for the sdba module -class Parametrizable(dict): +class Parametrizable(UserDict): """Helper base class resembling a dictionary. This object is _completely_ defined by the content of its internal dictionary, accessible through item access @@ -35,24 +36,23 @@ class Parametrizable(dict): def __getstate__(self): """For (json)pickle, a Parametrizable should be defined by its internal dict only.""" - return self.parameters + return self.data def __setstate__(self, state): """For (json)pickle, a Parametrizable in only defined by its internal dict.""" - self.update(state) + # Unpickling skips the init, so we must _set_ data, we can't just update it - it's not there yet + self.data = {**state} def __getattr__(self, attr): """Get attributes.""" - try: - return self.__getitem__(attr) - except KeyError as err: - # Raise the proper error type for getattr - raise AttributeError(*err.args) from err + if attr == "data" or attr not in self.data: + return self.__getattribute__(attr) + return self.data[attr] @property def parameters(self) -> dict: """All parameters as a dictionary. Read-only.""" - return {**self} + return {**self.data} def __repr__(self) -> str: """Return a string representation.""" From 446dc3ff686fca0b345965e14e3655985f4e4fb9 Mon Sep 17 00:00:00 2001 From: Pascal Bourgault Date: Tue, 12 Nov 2024 11:48:59 -0500 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Trevor James Smith <10819524+Zeitsperre@users.noreply.github.com> --- CHANGELOG.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e1fca65e7..e00a7567d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -8,11 +8,11 @@ Contributors to this version: Trevor James Smith (:user:`Zeitsperre`), Pascal Bo Breaking changes ---------------- -* The minimum required version of `dask` has been increased to `2024.8.1`. `dask` versions at or above `2024.11` are not yet supported. (:issue:`1992`, :pull:`1991`). +* The minimum required version of `dask` has been increased to `2024.8.1`. (:issue:`1992`, :pull:`1991`). Bug fixes ^^^^^^^^^ -* Fixes ``xclim.sdba.Grouper`` and other classes for usage with dask 2024.11 (:issue:`1992`, :pull:`1993`). +* Fixed pickling issue with ``xclim.sdba.Grouper`` and other classes for usage with `dask>=2024.11`. (:issue:`1992`, :pull:`1993`). v0.53.2 (2024-10-31) --------------------