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

Cannot slice a track when StatesLengthLimiter is used #1018

Open
narykov opened this issue May 20, 2024 · 2 comments
Open

Cannot slice a track when StatesLengthLimiter is used #1018

narykov opened this issue May 20, 2024 · 2 comments

Comments

@narykov
Copy link

narykov commented May 20, 2024

I'd like to use the StatesLengthLimiter wrapper for track initiation when processing a longer dataset. However, when I try slicing the resulting track, I receive this error:

Traceback (most recent call last):
File "/Users/alexeynarykov/miniconda3/envs/godot_devel/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3526, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
track_slice = next(iter(tracks))[1:]
File "/Users/alexeynarykov/Workspace/GitHub/Stone-Soup-ESA/stonesoup/types/state.py", line 308, in getitem
return StateMutableSequence(self.states.getitem(index))
TypeError: 'slice' object cannot be interpreted as an integer

An example based on '09_Initiators_&_Deleters.py' is provided here. The wrapper definition is on line 173 and slicing is attempted on line 213. When the wrapper definition is suppressed, the error is not showing up and the track slicing works OK.

@sdhiscocks
Copy link
Member

Seems to be a limitation of deque that states length limiter use. Work around for now would be to use track_slice = list(next(iter(tracks)))[1:]

There are other solutions as well.

@sdhiscocks
Copy link
Member

If all you want to do is [1:] this would be most performant I think track_slice = next(iter(tracks)).states.copy(); track_slice.popleft()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants