diff --git a/amber/src/main/python/core/models/tuple.py b/amber/src/main/python/core/models/tuple.py index 1f319b6a4f4..49e862d091f 100644 --- a/amber/src/main/python/core/models/tuple.py +++ b/amber/src/main/python/core/models/tuple.py @@ -192,7 +192,7 @@ def __init__( assert len(tuple_like) != 0 self._field_data: "OrderedDict[str, Field]" if isinstance(tuple_like, Tuple): - self._field_data = tuple_like._field_data + self._field_data = tuple_like._field_data.copy() elif isinstance(tuple_like, pandas.Series): self._field_data = OrderedDict(tuple_like.to_dict()) else: diff --git a/amber/src/test/python/core/models/test_tuple.py b/amber/src/test/python/core/models/test_tuple.py index aff43faa881..5827c2d0ad8 100644 --- a/amber/src/test/python/core/models/test_tuple.py +++ b/amber/src/test/python/core/models/test_tuple.py @@ -42,6 +42,16 @@ def test_tuple_from_dict(self, target_tuple): def test_tuple_from_series(self, target_tuple): assert Tuple(pandas.Series({"x": 1, "y": "a"})) == target_tuple + def test_tuple_copy_has_independent_field_storage(self, target_tuple): + copied = Tuple(target_tuple) + assert copied == target_tuple + + copied["x"] = 2 + target_tuple["y"] = "b" + + assert target_tuple["x"] == 1 + assert copied["y"] == "a" + def test_tuple_as_key_value_pairs(self, target_tuple): assert target_tuple.as_key_value_pairs() == [("x", 1), ("y", "a")]