Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shallow copy track in smoothers #1126

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

sdhiscocks
Copy link
Member

Resolves #1125

@sdhiscocks sdhiscocks requested a review from a team as a code owner February 20, 2025 16:47
@sdhiscocks sdhiscocks requested review from orosoman-dstl and spike-dstl and removed request for a team February 20, 2025 16:47
Copy link

codecov bot commented Feb 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.70%. Comparing base (9393fe7) to head (12b962f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1126      +/-   ##
==========================================
- Coverage   93.72%   93.70%   -0.03%     
==========================================
  Files         217      217              
  Lines       14430    14431       +1     
  Branches     1963     1963              
==========================================
- Hits        13525    13522       -3     
- Misses        644      646       +2     
- Partials      261      263       +2     
Flag Coverage Δ
integration 65.60% <33.33%> (+0.03%) ⬆️
unittests 91.00% <100.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

# replacement object for the original track states.
smoothed_track = copy.deepcopy(track, {id(track.states): smoothed_states})
# Shallow copy existing track, overwriting states
smoothed_track = copy.copy(track)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may have the (undesirable?) effect of changes in the original track's metadata being inadvertently reflected in the smoothed track's metadata.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also add shallow copy of the dictionaries of meta data?

diff --git a/stonesoup/types/tests/test_track.py b/stonesoup/types/tests/test_track.py
index 9c226e78..9ca8754b 100644
--- a/stonesoup/types/tests/test_track.py
+++ b/stonesoup/types/tests/test_track.py
@@ -201,7 +201,7 @@ def test_copy():
         assert original_state is copied_state
 
     for original_metadata, copied_metadata in zip(track.metadatas, copied_track.metadatas):
-        assert original_metadata is copied_metadata
+        assert original_metadata == copied_metadata
 
     assert len(track) == 3
     assert len(copied_track) == 3
diff --git a/stonesoup/types/track.py b/stonesoup/types/track.py
index 5a904b85..45f8b9fc 100644
--- a/stonesoup/types/track.py
+++ b/stonesoup/types/track.py
@@ -50,7 +50,7 @@ class Track(StateMutableSequence):
 
     def __copy__(self):
         inst = super().__copy__()
-        inst.__dict__['metadatas'] = copy.copy(self.__dict__['metadatas'])
+        inst.__dict__['metadatas'] = list(copy.copy(md) for md in self.__dict__['metadatas'])
         return inst
 
     def insert(self, index, value):

I think this is reasonable to be part of shallow copy as well, as Track object is already manipulating and copying these dictionaries itself when states are added/removed.

@sdhiscocks sdhiscocks requested a review from sglvladi February 26, 2025 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kalman smoother deep copy - unpickable, loose reference
2 participants