nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: SpikeInterface/spikeinterface
Pull request #2364 (2023-12-20 12:54:36)

Add `rename_channels` method to recording extractors
Easier for users to discover this method with tab completion instead of having to find out by themselves that they need to use channel slice of which this is a particular case. 




Patch:
diff --git a/src/spikeinterface/core/baserecording.py b/src/spikeinterface/core/baserecording.py
index 802578426..3941d0434 100644
--- a/src/spikeinterface/core/baserecording.py
+++ b/src/spikeinterface/core/baserecording.py
@@ -548,6 +548,23 @@ class BaseRecording(BaseRecordingSnippets):
             if time_vector is not None:
                 np.save(folder / f"times_cached_seg{segment_index}.npy", time_vector)
 
+    def rename_channels(self, new_channel_ids: list | np.array | tuple):
+        """
+        Returns a new recording object with renamed channel ids.
+
+        Parameters
+        ----------
+        new_channel_ids : list or np.array or tuple
+            The new channel ids. They are mapped positionally to the old channel ids.
+        """
+        from .channelslice import ChannelSliceRecording
+
+        assert len(new_channel_ids) == self.get_num_channels(), (
+            "new_channel_ids must have the same length as the " "number of channels in the recording"
+        )
+
+        return ChannelSliceRecording(self, renamed_channel_ids=new_channel_ids)
+
     def _channel_slice(self, channel_ids, renamed_channel_ids=None):
         from .channelslice import ChannelSliceRecording
 


Test patch:
diff --git a/src/spikeinterface/core/tests/test_baserecording.py b/src/spikeinterface/core/tests/test_baserecording.py
index 4326cd15a..2986b8798 100644
--- a/src/spikeinterface/core/tests/test_baserecording.py
+++ b/src/spikeinterface/core/tests/test_baserecording.py
@@ -345,5 +345,12 @@ def test_BaseRecording():
     assert np.allclose(rec_u.get_traces(cast_unsigned=True), rec_i.get_traces().astype("float"))
 
 
+def test_rename_channels():
+    recording = generate_recording(durations=[1.0], num_channels=3)
+    renamed_recording = recording.rename_channels(new_channel_ids=["a", "b", "c"])
+    renamed_channel_ids = renamed_recording.get_channel_ids()
+    assert np.array_equal(renamed_channel_ids, ["a", "b", "c"])
+
+
 if __name__ == "__main__":
     test_BaseRecording()
Repository: SpikeInterface/spikeinterface
Pull request #2511 (2024-02-23 09:35:19)

Fix mutually exclusive keys in job_kwargs
@yger : can you check this and tell me if it fixes your bug ?

@alejoe91 : this should go also in the bug fix release


Patch:
diff --git a/src/spikeinterface/core/job_tools.py b/src/spikeinterface/core/job_tools.py
index 0eec3e6b8..981ad6320 100644
--- a/src/spikeinterface/core/job_tools.py
+++ b/src/spikeinterface/core/job_tools.py
@@ -50,6 +50,14 @@ job_keys = (
     "max_threads_per_process",
 )
 
+# theses key are the same and should not be in th final dict
+_mutually_exclusive = (
+    "total_memory",
+    "chunk_size",
+    "chunk_memory",
+    "chunk_duration",
+)
+
 
 def fix_job_kwargs(runtime_job_kwargs):
     from .globals import get_global_job_kwargs
@@ -60,6 +68,14 @@ def fix_job_kwargs(runtime_job_kwargs):
         assert k in job_keys, (
             f"{k} is not a valid job keyword argument. " f"Available keyword arguments are: {list(job_keys)}"
         )
+
+    # remove mutually exclusive from global job kwargs
+    for k, v in runtime_job_kwargs.items():
+        if k in _mutually_exclusive and v is not None:
+            for key_to_remove in _mutually_exclusive:
+                if key_to_remove in job_kwargs:
+                    job_kwargs.pop(key_to_remove)
+
     # remove None
     runtime_job_kwargs_exclude_none = runtime_job_kwargs.copy()
     for job_key, job_value in runtime_job_kwargs.items():


Test patch:
diff --git a/src/spikeinterface/core/tests/test_job_tools.py b/src/spikeinterface/core/tests/test_job_tools.py
index a904e4dd3..1bfe3a5e7 100644
--- a/src/spikeinterface/core/tests/test_job_tools.py
+++ b/src/spikeinterface/core/tests/test_job_tools.py
@@ -1,7 +1,7 @@
 import pytest
 import os
 
-from spikeinterface.core import generate_recording
+from spikeinterface.core import generate_recording, set_global_job_kwargs, get_global_job_kwargs
 
 from spikeinterface.core.job_tools import (
     divide_segment_into_chunks,
@@ -190,6 +190,19 @@ def test_fix_job_kwargs():
         job_kwargs = dict(n_jobs=0, progress_bar=False, chunk_duration="1s", other_param="other")
         fixed_job_kwargs = fix_job_kwargs(job_kwargs)
 
+    # test mutually exclusive
+    _old_global = get_global_job_kwargs().copy()
+    set_global_job_kwargs(chunk_memory="50M")
+    job_kwargs = dict()
+    fixed_job_kwargs = fixed_job_kwargs = fix_job_kwargs(job_kwargs)
+    assert "chunk_memory" in fixed_job_kwargs
+
+    job_kwargs = dict(chunk_duration="300ms")
+    fixed_job_kwargs = fixed_job_kwargs = fix_job_kwargs(job_kwargs)
+    assert "chunk_memory" not in fixed_job_kwargs
+    assert fixed_job_kwargs["chunk_duration"] == "300ms"
+    set_global_job_kwargs(**_old_global)
+
 
 def test_split_job_kwargs():
     kwargs = dict(n_jobs=2, progress_bar=False, other_param="other")
@@ -204,6 +217,6 @@ if __name__ == "__main__":
     # test_divide_segment_into_chunks()
     # test_ensure_n_jobs()
     # test_ensure_chunk_size()
-    test_ChunkRecordingExecutor()
-    # test_fix_job_kwargs()
+    # test_ChunkRecordingExecutor()
+    test_fix_job_kwargs()
     # test_split_job_kwargs()