Skip to content

Commit a55ba4e

Browse files
authored
Merge branch 'main' into separate_open_ephys
2 parents 1a4383f + 877d136 commit a55ba4e

4 files changed

Lines changed: 34 additions & 5 deletions

File tree

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ repos:
66
- id: end-of-file-fixer
77
- id: trailing-whitespace
88
- repo: https://github.com/psf/black-pre-commit-mirror
9-
rev: 26.1.0
9+
rev: 26.3.1
1010
hooks:
1111
- id: black
1212
files: ^src/|^tests/
1313
- repo: https://github.com/codespell-project/codespell
1414
# Configuration for codespell is in .pre-commit-config.yaml
15-
rev: v2.4.1
15+
rev: v2.4.2
1616
hooks:
1717
- id: codespell
1818
additional_dependencies:

src/probeinterface/probe.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -570,14 +570,15 @@ def set_contact_ids(self, contact_ids: np.array | list):
570570
self._contact_ids = None
571571
return
572572

573-
assert np.unique(contact_ids).size == contact_ids.size, "Contact ids have to be unique within a Probe"
574-
575573
if contact_ids.size != self.get_contact_count():
576-
ValueError(
574+
raise ValueError(
577575
f"contact_ids {contact_ids.size} do not have the same size "
578576
f"as number of contacts {self.get_contact_count()}"
579577
)
580578

579+
if np.unique(contact_ids).size != contact_ids.size:
580+
raise ValueError("contact_ids must be unique within a Probe")
581+
581582
if contact_ids.dtype.kind != "U":
582583
contact_ids = contact_ids.astype("U")
583584

tests/conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import matplotlib
2+
3+
# Force a non-GUI backend for all tests
4+
matplotlib.use("Agg", force=True)

tests/test_probegroup.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,30 @@ def test_probegroup_allows_duplicate_positions_across_probes():
9292
assert len(group.probes) == 2
9393

9494

95+
def test_set_contact_ids_rejects_within_probe_duplicates():
96+
"""Setting duplicate contact_ids within a single probe raises ValueError."""
97+
from probeinterface import Probe
98+
99+
positions = np.array([[0, 0], [10, 10]])
100+
probe = Probe(ndim=2, si_units="um")
101+
probe.set_contacts(positions=positions, shapes="circle", shape_params={"radius": 5})
102+
103+
with pytest.raises(ValueError, match="unique within a Probe"):
104+
probe.set_contact_ids(["a", "a"])
105+
106+
107+
def test_set_contact_ids_rejects_wrong_size():
108+
"""Setting contact_ids with wrong count raises ValueError."""
109+
from probeinterface import Probe
110+
111+
positions = np.array([[0, 0], [10, 10]])
112+
probe = Probe(ndim=2, si_units="um")
113+
probe.set_contacts(positions=positions, shapes="circle", shape_params={"radius": 5})
114+
115+
with pytest.raises(ValueError, match="do not have the same size"):
116+
probe.set_contact_ids(["a", "b", "c"])
117+
118+
95119
if __name__ == "__main__":
96120
test_probegroup()
97121
# ~ test_probegroup_3d()

0 commit comments

Comments
 (0)