Skip to content

Commit

Permalink
fix: Copy data when casting a matrix
Browse files Browse the repository at this point in the history
If just assigning the values, then the data is shared and changing it affects everyone that has a reference to it.

PR #53: #53
Co-authored-by: Vlad Dumitrescu <vlad.dumitrescu@volvocars.com>
  • Loading branch information
vladdu committed Jun 18, 2022
1 parent fc34cd6 commit 13ec81a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/dependenpy/structures.py
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import copy
import json
from typing import TYPE_CHECKING, Any

Expand Down Expand Up @@ -94,8 +95,8 @@ def cast(keys: list[str], data: list[list[int]]) -> Matrix: # noqa: WPS602
A new matrix.
"""
matrix = Matrix()
matrix.keys = keys
matrix.data = data
matrix.keys = copy.deepcopy(keys)
matrix.data = copy.deepcopy(data)
return matrix

@property
Expand Down

0 comments on commit 13ec81a

Please sign in to comment.