@@ -337,7 +337,10 @@ def set_contacts(
337337 Defines the two axes of the contact plane for each electrode.
338338 The third dimension corresponds to the probe `ndim` (2d or 3d).
339339 contact_ids: array[str] | None, default: None
340- Defines the contact ids for the contacts. If None, contact ids are not assigned.
340+ Defines the contact ids for the contacts. If None, contact ids are
341+ auto-generated as the zero-indexed strings ``["0", "1", ..., str(n - 1)]``
342+ so a Probe always carries a stable, slice-invariant handle for each
343+ contact. Pass an explicit array to override.
341344 shank_ids : array[str] | None, default: None
342345 Defines the shank ids for the contacts. If None, then
343346 these are assigned to a unique Shank.
@@ -379,8 +382,9 @@ def set_contacts(
379382 plane_axes = np .array (plane_axes )
380383 self ._contact_plane_axes = plane_axes
381384
382- if contact_ids is not None :
383- self .set_contact_ids (contact_ids )
385+ if contact_ids is None :
386+ contact_ids = np .arange (n ).astype (str )
387+ self .set_contact_ids (contact_ids )
384388
385389 if shank_ids is None :
386390 # self._shank_ids = np.zeros(n, dtype=str)
@@ -567,8 +571,9 @@ def set_contact_ids(self, contact_ids: np.ndarray | list):
567571 """
568572 contact_ids = np .asarray (contact_ids )
569573 if np .all ([c == "" for c in contact_ids ]):
570- self ._contact_ids = None
571- return
574+ # Backward compat: previous versions serialized "unset" as empty
575+ # strings. A Probe now always carries contact_ids, so regenerate.
576+ contact_ids = np .arange (self .get_contact_count ()).astype (str )
572577
573578 if contact_ids .size != self .get_contact_count ():
574579 raise ValueError (
@@ -1081,10 +1086,7 @@ def to_numpy(self, complete: bool = False) -> np.ndarray:
10811086 if self ._contact_sides is not None :
10821087 arr ["contact_sides" ] = self .contact_sides
10831088
1084- if self .contact_ids is None :
1085- arr ["contact_ids" ] = ["" ] * self .get_contact_count ()
1086- else :
1087- arr ["contact_ids" ] = self .contact_ids
1089+ arr ["contact_ids" ] = self .contact_ids
10881090
10891091 if complete :
10901092 arr ["si_units" ] = self .si_units
0 commit comments