-
Notifications
You must be signed in to change notification settings - Fork 144
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
base: main
Are you sure you want to change the base?
Conversation
Resolves #1125
Codecov ReportAll modified and coverable lines are covered by tests ✅
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
# 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Resolves #1125