You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I'm trying to merge two blocks together, each having one segment, into one block with two segments. But I have problems calling merge since I have spike trains in groups. Why am I told SpikeTrain can only have Segment, not Group parents? No errors popped up before merging. From what I understand, an object can be in more than one container, but only have one parent.
---------------------------------------------------------------------------TypeErrorTraceback (mostrecentcalllast)
/home/kyle/scratch/python-neo/test.pyinline2
[16](file:///home/kyle/scratch/python-neo/test.py?line=15) # %%----> [17](file:///home/kyle/scratch/python-neo/test.py?line=16) blocks[0].merge(blocks[1])
[18](file:///home/kyle/scratch/python-neo/test.py?line=17) blocks[0]
File [~/scratch/python-neo/neo/core/container.py:491](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/kyle/scratch/python-neo/~/scratch/python-neo/neo/core/container.py:491), inContainer.merge(self, other)
[489](file:///home/kyle/scratch/python-neo/neo/core/container.py?line=488) continue
[490](file:///home/kyle/scratch/python-neo/neo/core/container.py?line=489) ifobj.nameinlookup:
--> [491](file:///home/kyle/scratch/python-neo/neo/core/container.py?line=490) lookup[obj.name].merge(obj)
[492](file:///home/kyle/scratch/python-neo/neo/core/container.py?line=491) else:
[493](file:///home/kyle/scratch/python-neo/neo/core/container.py?line=492) lookup[obj.name] =objFile [~/scratch/python-neo/neo/core/container.py:519](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/kyle/scratch/python-neo/~/scratch/python-neo/neo/core/container.py:519), inContainer.merge(self, other)
[516](file:///home/kyle/scratch/python-neo/neo/core/container.py?line=515) getattr(self, container).append(obj)
[517](file:///home/kyle/scratch/python-neo/neo/core/container.py?line=516) # if self.__class__.__name__ in obj._parent_objects:
[518](file:///home/kyle/scratch/python-neo/neo/core/container.py?line=517) # obj.set_parent(self)--> [519](file:///home/kyle/scratch/python-neo/neo/core/container.py?line=518) obj.set_parent(self)
[521](file:///home/kyle/scratch/python-neo/neo/core/container.py?line=520) # use the BaseNeo merge as well
[522](file:///home/kyle/scratch/python-neo/neo/core/container.py?line=521) super().merge(other)
File [~/scratch/python-neo/neo/core/baseneo.py:369](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/kyle/scratch/python-neo/~/scratch/python-neo/neo/core/baseneo.py:369), inBaseNeo.set_parent(self, obj)
[364](file:///home/kyle/scratch/python-neo/neo/core/baseneo.py?line=363) """ [365](file:///home/kyle/scratch/python-neo/neo/core/baseneo.py?line=364) Set the appropriate "parent" attribute of this object [366](file:///home/kyle/scratch/python-neo/neo/core/baseneo.py?line=365) according to the type of "obj" [367](file:///home/kyle/scratch/python-neo/neo/core/baseneo.py?line=366) """
[368](file:///home/kyle/scratch/python-neo/neo/core/baseneo.py?line=367) ifobj.__class__.__name__notinself._parent_objects:
--> [369](file:///home/kyle/scratch/python-neo/neo/core/baseneo.py?line=368) raiseTypeError("{} can only have parents of type {}, not {}".format(
[370](file:///home/kyle/scratch/python-neo/neo/core/baseneo.py?line=369) self.__class__.__name__, self._parent_objects, obj.__class__.__name__))
[371](file:///home/kyle/scratch/python-neo/neo/core/baseneo.py?line=370) loc=self._parent_objects.index(obj.__class__.__name__)
[372](file:///home/kyle/scratch/python-neo/neo/core/baseneo.py?line=371) parent_attr=self._parent_attrs[loc]
TypeError: SpikeTraincanonlyhaveparentsoftype ('Segment',), notGroup
Expected behaviour
The blocks to merge with set_parent on children objects only applied to the true parent. I don't know enough of the codebase to know if this will cause problems anywhere else, but changing obj.set_parent(self) in Container.merge() to this does the trick:
Describe the bug
I'm trying to merge two blocks together, each having one segment, into one block with two segments. But I have problems calling merge since I have spike trains in groups. Why am I told SpikeTrain can only have Segment, not Group parents? No errors popped up before merging. From what I understand, an object can be in more than one container, but only have one parent.
To Reproduce
Output:
Expected behaviour
The blocks to merge with
set_parent
on children objects only applied to the true parent. I don't know enough of the codebase to know if this will cause problems anywhere else, but changingobj.set_parent(self)
inContainer.merge()
to this does the trick:Then I get what I expected out of the MRE:
Environment:
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: