Skip to content

Commit fa50091

Browse files
authored
Merge pull request #3304 from tabedzki/main
Adding return type annotations
2 parents b3f9793 + e6b99da commit fa50091

31 files changed

Lines changed: 69 additions & 63 deletions

src/spikeinterface/comparison/comparisontools.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
"""
44

55
from __future__ import annotations
6-
7-
86
import numpy as np
97

108

11-
def count_matching_events(times1, times2, delta=10):
9+
def count_matching_events(times1, times2: np.ndarray | list, delta: int = 10):
1210
"""
1311
Counts matching events.
1412
@@ -39,7 +37,7 @@ def count_matching_events(times1, times2, delta=10):
3937
return len(inds2) + 1
4038

4139

42-
def compute_agreement_score(num_matches, num1, num2):
40+
def compute_agreement_score(num_matches: int, num1: int, num2: int) -> float:
4341
"""
4442
Computes agreement score.
4543
@@ -232,8 +230,8 @@ def make_match_count_matrix(sorting1, sorting2, delta_frames, ensure_symmetry=Fa
232230
And the minimum of the two results is taken.
233231
Returns
234232
-------
235-
matching_matrix : ndarray
236-
A 2D numpy array of shape `(num_units_train1, num_units_train2)`. Each element `[i, j]` represents
233+
matching_matrix : pd.DataFrame
234+
A 2D pandas DataFrame of shape `(num_units_train1, num_units_train2)`. Each element `[i, j]` represents
237235
the count of matching spike pairs between unit `i` from `spike_frames_train1` and unit `j` from `spike_frames_train2`.
238236
239237
Notes
@@ -348,7 +346,7 @@ def make_agreement_scores(sorting1, sorting2, delta_frames, ensure_symmetry=True
348346
And the minimum of the two results is taken.
349347
Returns
350348
-------
351-
agreement_scores : array (float)
349+
agreement_scores : pd.DataFrame
352350
The agreement score matrix.
353351
"""
354352
import pandas as pd
@@ -408,9 +406,9 @@ def make_possible_match(agreement_scores, min_score):
408406
409407
Returns
410408
-------
411-
best_match_12 : pd.Series
409+
best_match_12 : dict[NDArray]
412410
413-
best_match_21 : pd.Series
411+
best_match_21 : dict[NDArray]
414412
415413
"""
416414
unit1_ids = np.array(agreement_scores.index)
@@ -433,7 +431,7 @@ def make_possible_match(agreement_scores, min_score):
433431
return possible_match_12, possible_match_21
434432

435433

436-
def make_best_match(agreement_scores, min_score):
434+
def make_best_match(agreement_scores, min_score) -> "tuple[pd.Series, pd.Series]":
437435
"""
438436
Given an agreement matrix and a min_score threshold.
439437
return a dict a best match for each units independently of others.

src/spikeinterface/core/baseevent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class BaseEventSegment(BaseSegment):
137137
def __init__(self):
138138
BaseSegment.__init__(self)
139139

140-
def get_event_times(self, channel_id: int | str, start_time: float, end_time: float):
140+
def get_event_times(self, channel_id: int | str, start_time: float, end_time: float) -> np.ndarray:
141141
"""Returns event timestamps of a channel in seconds
142142
Parameters
143143
----------

src/spikeinterface/core/baserecording.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ def get_traces(
305305
order: "C" | "F" | None = None,
306306
return_scaled: bool = False,
307307
cast_unsigned: bool = False,
308-
):
308+
) -> np.ndarray:
309309
"""Returns traces from recording.
310310
311311
Parameters

src/spikeinterface/core/core_tools.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,7 @@ def set_value_in_extractor_dict(extractor_dict: dict, access_path: tuple, new_va
257257
258258
Returns
259259
-------
260-
dict
261-
The modified dictionary
260+
None
262261
"""
263262

264263
current = extractor_dict
@@ -439,7 +438,7 @@ def make_paths_relative(input_dict: dict, relative_folder: str | Path) -> dict:
439438
return output_dict
440439

441440

442-
def make_paths_absolute(input_dict, base_folder):
441+
def make_paths_absolute(input_dict, base_folder) -> dict:
443442
"""
444443
Recursively transform a dict describing an BaseExtractor to make every path absolute given a base_folder.
445444
@@ -632,7 +631,7 @@ def normal_pdf(x, mu: float = 0.0, sigma: float = 1.0):
632631
return 1 / (sigma * np.sqrt(2 * np.pi)) * np.exp(-((x - mu) ** 2) / (2 * sigma**2))
633632

634633

635-
def retrieve_importing_provenance(a_class):
634+
def retrieve_importing_provenance(a_class) -> dict:
636635
"""
637636
Retrieve the import provenance of a class, including its import name (that consists of the class name and the module),
638637
the top-level module, and the module version.

src/spikeinterface/core/generate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def generate_recording(
3333
set_probe: bool | None = True,
3434
ndim: int | None = 2,
3535
seed: int | None = None,
36-
) -> BaseRecording:
36+
) -> NumpySorting:
3737
"""
3838
Generate a lazy recording object.
3939
Useful for testing API and algos.

src/spikeinterface/core/old_api_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def get_unit_ids(self):
8888
"""
8989
return list(self._unit_map.keys())
9090

91-
def get_unit_spike_train(self, unit_id, start_frame=None, end_frame=None):
91+
def get_unit_spike_train(self, unit_id, start_frame=None, end_frame=None) -> np.ndarray:
9292
"""This function extracts spike frames from the specified unit.
9393
It will return spike frames from within three ranges:
9494
@@ -122,7 +122,7 @@ def get_unit_spike_train(self, unit_id, start_frame=None, end_frame=None):
122122
unit_id=self._unit_map[unit_id], segment_index=0, start_frame=start_frame, end_frame=end_frame
123123
)
124124

125-
def get_units_spike_train(self, unit_ids=None, start_frame=None, end_frame=None):
125+
def get_units_spike_train(self, unit_ids=None, start_frame=None, end_frame=None) -> list[np.ndarray]:
126126
"""This function extracts spike frames from the specified units.
127127
128128
Parameters
@@ -137,7 +137,7 @@ def get_units_spike_train(self, unit_ids=None, start_frame=None, end_frame=None)
137137
138138
Returns
139139
-------
140-
spike_train: numpy.ndarray
140+
spike_train: list[numpy.ndarray]
141141
An 2D array containing all the frames for each spike in the
142142
specified units given the range of start and end frames
143143
"""
@@ -146,7 +146,7 @@ def get_units_spike_train(self, unit_ids=None, start_frame=None, end_frame=None)
146146
spike_trains = [self.get_unit_spike_train(uid, start_frame, end_frame) for uid in unit_ids]
147147
return spike_trains
148148

149-
def get_sampling_frequency(self):
149+
def get_sampling_frequency(self) -> float:
150150
"""
151151
It returns the sampling frequency.
152152

src/spikeinterface/core/recording_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ def get_noise_levels(
640640
method: Literal["mad", "std"] = "mad",
641641
force_recompute: bool = False,
642642
**random_chunk_kwargs,
643-
):
643+
) -> np.ndarray:
644644
"""
645645
Estimate noise for each channel using MAD methods.
646646
You can use standard deviation with `method="std"`

src/spikeinterface/core/sortinganalyzer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def create_sorting_analyzer(
4444
return_scaled=True,
4545
overwrite=False,
4646
**sparsity_kwargs,
47-
):
47+
) -> "SortingAnalyzer":
4848
"""
4949
Create a SortingAnalyzer by pairing a Sorting and the corresponding Recording.
5050
@@ -145,7 +145,7 @@ def create_sorting_analyzer(
145145
return sorting_analyzer
146146

147147

148-
def load_sorting_analyzer(folder, load_extensions=True, format="auto", storage_options=None):
148+
def load_sorting_analyzer(folder, load_extensions=True, format="auto", storage_options=None) -> "SortingAnalyzer":
149149
"""
150150
Load a SortingAnalyzer object from disk.
151151
@@ -1123,7 +1123,7 @@ def get_num_units(self) -> int:
11231123
return self.sorting.get_num_units()
11241124

11251125
## extensions zone
1126-
def compute(self, input, save=True, extension_params=None, verbose=False, **kwargs):
1126+
def compute(self, input, save=True, extension_params=None, verbose=False, **kwargs) -> "AnalyzerExtension | None":
11271127
"""
11281128
Compute one extension or several extensiosn.
11291129
Internally calls compute_one_extension() or compute_several_extensions() depending on the input type.
@@ -1190,7 +1190,7 @@ def compute(self, input, save=True, extension_params=None, verbose=False, **kwar
11901190
else:
11911191
raise ValueError("SortingAnalyzer.compute() need str, dict or list")
11921192

1193-
def compute_one_extension(self, extension_name, save=True, verbose=False, **kwargs):
1193+
def compute_one_extension(self, extension_name, save=True, verbose=False, **kwargs) -> "AnalyzerExtension":
11941194
"""
11951195
Compute one extension.
11961196

src/spikeinterface/core/waveform_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ def estimate_templates_with_accumulator(
791791
return_std: bool = False,
792792
verbose: bool = False,
793793
**job_kwargs,
794-
):
794+
) -> np.ndarray:
795795
"""
796796
This is a fast implementation to compute template averages and standard deviations.
797797
This is useful to estimate sparsity without the need to allocate large waveform buffers.

src/spikeinterface/core/waveforms_extractor_backwards_compatibility.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ def load_waveforms(
373373
with_recording: bool = True,
374374
sorting: Optional[BaseSorting] = None,
375375
output="MockWaveformExtractor",
376-
):
376+
) -> MockWaveformExtractor | SortingAnalyzer:
377377
"""
378378
This read an old WaveformsExtactor folder (folder or zarr) and convert it into a SortingAnalyzer or MockWaveformExtractor.
379379

0 commit comments

Comments
 (0)