From 09afb27af38366d9c6f06b0eceaed17af75f04b4 Mon Sep 17 00:00:00 2001 From: ahuang11 Date: Tue, 21 May 2024 22:10:06 -0700 Subject: [PATCH 1/5] fix pickling state --- holoviews/core/dimension.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/holoviews/core/dimension.py b/holoviews/core/dimension.py index 069d5c5742..2cfb7d85c0 100644 --- a/holoviews/core/dimension.py +++ b/holoviews/core/dimension.py @@ -749,7 +749,7 @@ def __setstate__(self, d): self.param.warning("Could not unpickle custom style information.") d['_id'] = opts_id self.__dict__.update(d) - super().__setstate__({}) + super().__setstate__(d) class Dimensioned(LabelledData): From eefacbf03a583249b4c4e598e6043476f6fe0e71 Mon Sep 17 00:00:00 2001 From: ahuang11 Date: Tue, 21 May 2024 22:18:42 -0700 Subject: [PATCH 2/5] add test --- holoviews/tests/core/test_dimensioned.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/holoviews/tests/core/test_dimensioned.py b/holoviews/tests/core/test_dimensioned.py index dbd4743bc9..ef3f14efba 100644 --- a/holoviews/tests/core/test_dimensioned.py +++ b/holoviews/tests/core/test_dimensioned.py @@ -1,5 +1,7 @@ import gc +import pickle +from holoviews.element.chart import Curve from holoviews.core.spaces import HoloMap from holoviews.core.element import Element from holoviews.core.options import Store, Keywords, Options, OptionTree @@ -253,3 +255,11 @@ def test_opts_clear_cleans_unused_tree(self): ExampleElement([]).opts(style_opt1='A').opts.clear() custom_options = Store._custom_options['backend_1'] self.assertEqual(len(custom_options), 0) + +class TestGetSetState: + + def test_pickle_roundtrip(self): + curve = Curve([0, 1, 2], kdims=["XAXIS"]) + roundtrip_curve = pickle.loads(pickle.dumps(curve)) + assert curve.kdims == roundtrip_curve.kdims + assert curve.vdims == roundtrip_curve.vdims From b022356cd0f94036f3f3e20043f330bed8cd9201 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro=20Hansen?= Date: Wed, 22 May 2024 08:45:37 +0200 Subject: [PATCH 3/5] Fix lint --- holoviews/tests/core/test_dimensioned.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/holoviews/tests/core/test_dimensioned.py b/holoviews/tests/core/test_dimensioned.py index b488e6d385..e91775c647 100644 --- a/holoviews/tests/core/test_dimensioned.py +++ b/holoviews/tests/core/test_dimensioned.py @@ -1,11 +1,10 @@ import gc import pickle -from holoviews.element.chart import Curve -from holoviews.core.spaces import HoloMap from holoviews.core.element import Element from holoviews.core.options import Keywords, Options, OptionTree, Store from holoviews.core.spaces import HoloMap +from holoviews.element.chart import Curve from ..utils import LoggingComparisonTestCase From 7be6ea5c81f9c6c1a1c21c6d562e549fa0e70f74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro=20Hansen?= Date: Thu, 6 Jun 2024 14:37:11 +0200 Subject: [PATCH 4/5] Remove 10 year old backwards code --- holoviews/core/dimension.py | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/holoviews/core/dimension.py b/holoviews/core/dimension.py index c54814220b..afbed928eb 100644 --- a/holoviews/core/dimension.py +++ b/holoviews/core/dimension.py @@ -715,36 +715,6 @@ def __getstate__(self): def __setstate__(self, d): "Restores options applied to this object." d = param_aliases(d) - - # Backwards compatibility for objects before id was made a property - opts_id = d['_id'] if '_id' in d else d.pop('id', None) - try: - load_options = Store.load_counter_offset is not None - if load_options: - matches = [k for k in d if k.startswith('_custom_option')] - for match in matches: - custom_id = int(match.split('_')[-1])+Store.load_counter_offset - if not isinstance(d[match], dict): - # Backward compatibility before multiple backends - backend_info = {'matplotlib':d[match]} - else: - backend_info = d[match] - for backend, info in backend_info.items(): - if backend not in Store._custom_options: - Store._custom_options[backend] = {} - Store._custom_options[backend][custom_id] = info - if backend_info: - if custom_id not in Store._weakrefs: - Store._weakrefs[custom_id] = [] - ref = weakref.ref(self, partial(cleanup_custom_options, custom_id)) - Store._weakrefs[opts_id].append(ref) - d.pop(match) - - if opts_id is not None: - opts_id += Store.load_counter_offset - except Exception: - self.param.warning("Could not unpickle custom style information.") - d['_id'] = opts_id self.__dict__.update(d) super().__setstate__(d) From f47ffea51356ca8916367211157fb889ddb40d2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro=20Hansen?= Date: Thu, 6 Jun 2024 15:08:44 +0200 Subject: [PATCH 5/5] Add back code --- holoviews/core/dimension.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/holoviews/core/dimension.py b/holoviews/core/dimension.py index afbed928eb..fa75b5a1ac 100644 --- a/holoviews/core/dimension.py +++ b/holoviews/core/dimension.py @@ -715,6 +715,26 @@ def __getstate__(self): def __setstate__(self, d): "Restores options applied to this object." d = param_aliases(d) + + load_options = Store.load_counter_offset is not None + if load_options: + matches = [k for k in d if k.startswith('_custom_option')] + for match in matches: + custom_id = int(match.split('_')[-1])+Store.load_counter_offset + for backend, info in d[match].items(): + if backend not in Store._custom_options: + Store._custom_options[backend] = {} + Store._custom_options[backend][custom_id] = info + if d[match]: + if custom_id not in Store._weakrefs: + Store._weakrefs[custom_id] = [] + ref = weakref.ref(self, partial(cleanup_custom_options, custom_id)) + Store._weakrefs[d["_id"]].append(ref) + d.pop(match) + + if d["_id"] is not None: + d["_id"] += Store.load_counter_offset + self.__dict__.update(d) super().__setstate__(d)