From a6fb8297efd8ad890b33256ce39eb173944143cb Mon Sep 17 00:00:00 2001 From: Antti Soininen Date: Fri, 5 Apr 2024 10:51:20 +0300 Subject: [PATCH] Make deep_copy_value() accept None --- spinedb_api/parameter_value.py | 2 +- tests/test_parameter_value.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/spinedb_api/parameter_value.py b/spinedb_api/parameter_value.py index 6f22264b..51a16ca1 100644 --- a/spinedb_api/parameter_value.py +++ b/spinedb_api/parameter_value.py @@ -1745,7 +1745,7 @@ def deep_copy_value(value): Returns: Any: deep-copied value """ - if isinstance(value, (Number, str)): + if isinstance(value, (Number, str)) or value is None: return value if isinstance(value, Array): return Array(value.values, value.value_type, value.index_name) diff --git a/tests/test_parameter_value.py b/tests/test_parameter_value.py index 1f4de335..fa75a838 100644 --- a/tests/test_parameter_value.py +++ b/tests/test_parameter_value.py @@ -1005,6 +1005,9 @@ def convert_map_to_dict(self): self.assertEqual(nested_map, {"A": {"a": -3.2, "b": -2.3}, "B": {"c": 3.2, "d": 2.3}}) def test_deep_copy_value_for_scalars(self): + x = None + copy_of_x = deep_copy_value(x) + self.assertIsNone(copy_of_x) x = 1.0 copy_of_x = deep_copy_value(x) self.assertEqual(x, copy_of_x)