python-neo icon indicating copy to clipboard operation
python-neo copied to clipboard

`container.filter` unsets the parent links of `SpikeTrain`s

Open Kleinjohann opened this issue 3 years ago • 0 comments

If a container.filter only returns SpikeTrain objects, they are returned as a SpikeTrainList. https://github.com/NeuralEnsemble/python-neo/blob/345d3392ee443994b8de58731cc9459e5308ff11/neo/core/container.py#L89-L90

The initialisation of this list overwrites the original parent links, causing the following behaviour:

import neo
import quantities as pq

seg = neo.Segment()
st = neo.SpikeTrain(times=[1]*pq.s, t_stop=2*pq.s)
seg.spiketrains.append(st)
print('before: ', st.segment)
filtered_st = seg.filter(objects=neo.SpikeTrain)
print('after: ', st.segment)

returns:

before:  <neo.core.segment.Segment object at 0x7fcb0bde3700>
after:  None

I was going to implement a fix myself, but I wasn't sure how to deal with the case of a block.filter returning spiketrains from different segments - the implementation of SpikeTrainList looks like it's only supposed to contain spiketrains that share the same segment.

Kleinjohann avatar Sep 21 '22 12:09 Kleinjohann