Skip to content

Commit 7b496b2

Browse files
authored
Merge pull request #414 from alejoe91/final-deprecations
Fix typing, deprecations, and update to Python3.10
2 parents 606d57e + 89d5ba8 commit 7b496b2

File tree

14 files changed

+81
-83
lines changed

14 files changed

+81
-83
lines changed

.github/workflows/full_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
python-version: ["3.9", "3.14"] # Lower and higher versions we support
20+
python-version: ["3.10", "3.14"] # Lower and higher versions we support
2121
os: [macos-latest, windows-latest, ubuntu-latest]
2222
steps:
2323
- uses: actions/checkout@v4

.github/workflows/publish-to-pypi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- name: Set up Python
1515
uses: actions/setup-python@v5
1616
with:
17-
python-version: "3.10"
17+
python-version: "3.11"
1818
- name: Install Tools
1919
run: |
2020
python -m pip install --upgrade pip

examples/ex_12_plot_values.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
fig, ax = plt.subplots()
3636
poly, poly_contour = plot_probe(probe, contacts_values=values,
37-
cmap='jet', ax=ax, contacts_kargs={'alpha' : 1}, title=False)
37+
cmap='jet', ax=ax, contact_kwargs={'alpha' : 1}, title=False)
3838
poly.set_clim(-2, 2)
3939
fig.colorbar(poly)
4040

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ authors = [
99

1010
description = "Python package to handle probe layout, geometry and wiring to device."
1111
readme = "README.md"
12-
requires-python = ">=3.9"
12+
requires-python = ">=3.10"
1313
classifiers = [
1414
"Programming Language :: Python :: 3",
1515
"License :: OSI Approved :: MIT License",

src/probeinterface/generator.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
44
"""
55

6-
from __future__ import annotations
76
import numpy as np
87

9-
from typing import Optional
8+
from typing import Literal
109

1110
from .probe import Probe
1211
from .probegroup import ProbeGroup
@@ -15,7 +14,7 @@
1514
_default_shape_to_params = {"circle": "radius", "square": "width", "rect": "height"}
1615

1716

18-
def generate_dummy_probe(elec_shapes: "circle" | "square" | "rect" = "circle") -> Probe:
17+
def generate_dummy_probe(elec_shapes: Literal["circle", "square", "rect"] = "circle") -> Probe:
1918
"""
2019
Generate a dummy probe with 3 columns and 32 contacts.
2120
Mainly used for testing and examples.
@@ -103,8 +102,8 @@ def generate_multi_columns_probe(
103102
num_contact_per_column: int | list[int] = 10,
104103
xpitch: float = 20,
105104
ypitch: float = 20,
106-
y_shift_per_column: Optional[np.array | list] = None,
107-
contact_shapes: "circle" | "rect" | "square" = "circle",
105+
y_shift_per_column: np.ndarray | list | None = None,
106+
contact_shapes: Literal["circle", "rect", "square"] = "circle",
108107
contact_shape_params: dict = {"radius": 6},
109108
) -> Probe:
110109
"""Generate a Probe with several columns.
@@ -119,7 +118,7 @@ def generate_multi_columns_probe(
119118
Pitch in x direction
120119
ypitch : float, default: 20
121120
Pitch in y direction
122-
y_shift_per_column : Optional[array-like], default: None
121+
y_shift_per_column : array-like | None, default: None
123122
Shift in y direction per column. It needs to have the same length as num_columns, by default None
124123
contact_shapes : "circle" | "rect" | "square", default: "circle"
125124
Shape of the contacts
@@ -167,7 +166,7 @@ def generate_multi_columns_probe(
167166
def generate_linear_probe(
168167
num_elec: int = 16,
169168
ypitch: float = 20,
170-
contact_shapes: "circle" | "rect" | "square" = "circle",
169+
contact_shapes: Literal["circle", "rect", "square"] = "circle",
171170
contact_shape_params: dict = {"radius": 6},
172171
) -> Probe:
173172
"""Generate a one-column linear probe.

src/probeinterface/io.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
1010
"""
1111

12-
from __future__ import annotations
1312
from pathlib import Path
14-
from typing import Union, Optional
1513
import re
1614
import warnings
1715
import json
@@ -108,7 +106,7 @@ def write_probeinterface(file: str | Path, probe_or_probegroup: Probe | ProbeGro
108106
tsv_label_map_to_probeinterface = {v: k for k, v in tsv_label_map_to_BIDS.items()}
109107

110108

111-
def read_BIDS_probe(folder: str | Path, prefix: Optional[str] = None) -> ProbeGroup:
109+
def read_BIDS_probe(folder: str | Path, prefix: str | None = None) -> ProbeGroup:
112110
"""
113111
Read to BIDS probe format.
114112
@@ -636,8 +634,8 @@ def read_3brain(file: str | Path, mea_pitch: float = None, electrode_width: floa
636634
def write_prb(
637635
file: str,
638636
probegroup: ProbeGroup,
639-
total_nb_channels: Optional[int] = None,
640-
radius: Optional[float] = None,
637+
total_nb_channels: int | None = None,
638+
radius: float | None = None,
641639
group_mode: str = "by_probe",
642640
):
643641
"""
@@ -664,9 +662,9 @@ def write_prb(
664662
The name of the file to be written
665663
probegroup: ProbeGroup
666664
The Probegroup to be used for writing
667-
total_nb_channels: Optional[int], default None
665+
total_nb_channels: int | None, default None
668666
***to do
669-
radius: Optional[float], default None
667+
radius: float | None, default None
670668
*** to do
671669
group_mode: str
672670
One of "by_probe" or "by_shank

src/probeinterface/library.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99
1010
"""
1111

12-
from __future__ import annotations
1312
import os
1413
import warnings
1514
from pathlib import Path
1615
from urllib.request import urlopen
1716
import requests
18-
from typing import Optional
1917

2018
from .io import read_probeinterface
19+
from .probe import Probe
2120

2221
# OLD URL on gin
2322
# public_url = "https://web.gin.g-node.org/spikeinterface/probeinterface_library/raw/master/"
@@ -37,7 +36,7 @@ def get_cache_folder() -> Path:
3736
return Path(os.path.expanduser("~")) / ".config" / "probeinterface" / "library"
3837

3938

40-
def download_probeinterface_file(manufacturer: str, probe_name: str, tag: Optional[str] = None) -> None:
39+
def download_probeinterface_file(manufacturer: str, probe_name: str, tag: str | None = None) -> None:
4140
"""Download the probeinterface file to the cache directory.
4241
Note that the file is itself a ProbeGroup but on the repo each file
4342
represents one probe.
@@ -65,7 +64,7 @@ def download_probeinterface_file(manufacturer: str, probe_name: str, tag: Option
6564
f.write(rem.read())
6665

6766

68-
def get_from_cache(manufacturer: str, probe_name: str, tag: Optional[str] = None) -> Optional["Probe"]:
67+
def get_from_cache(manufacturer: str, probe_name: str, tag: str | None = None) -> Probe | None:
6968
"""
7069
Get Probe from local cache
7170
@@ -105,8 +104,8 @@ def get_from_cache(manufacturer: str, probe_name: str, tag: Optional[str] = None
105104
def get_probe(
106105
manufacturer: str,
107106
probe_name: str,
108-
name: Optional[str] = None,
109-
tag: Optional[str] = None,
107+
name: str | None = None,
108+
tag: str | None = None,
110109
force_download: bool = False,
111110
) -> "Probe":
112111
"""

src/probeinterface/neuropixels_tools.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
88
"""
99

10-
from __future__ import annotations
1110
from pathlib import Path
12-
from typing import Union, Optional
1311
import warnings
1412
from packaging.version import parse
1513
import json
@@ -114,7 +112,7 @@ def get_probe_length(probe_part_number: str) -> int:
114112
return 10_000
115113

116114

117-
def make_mux_table_array(mux_information) -> np.array:
115+
def make_mux_table_array(mux_information) -> np.ndarray:
118116
"""
119117
Function to parse the mux_table from ProbeTable.
120118
@@ -210,7 +208,7 @@ def get_probe_contour_vertices(shank_width, tip_length, probe_length) -> list:
210208
return polygon_vertices
211209

212210

213-
def read_imro(file_path: Union[str, Path]) -> Probe:
211+
def read_imro(file_path: str | Path) -> Probe:
214212
"""
215213
Read probe position from the imro file used in input of SpikeGlx and Open-Ephys for neuropixels probes.
216214
@@ -571,7 +569,7 @@ def _annotate_probe_with_adc_sampling_info(probe: Probe, adc_sampling_table: str
571569
_annotate_contacts_from_mux_table(probe, adc_groups_array)
572570

573571

574-
def _read_imro_string(imro_str: str, imDatPrb_pn: Optional[str] = None) -> Probe:
572+
def _read_imro_string(imro_str: str, imDatPrb_pn: str | None = None) -> Probe:
575573
"""
576574
Parse the IMRO table when presented as a string and create a Probe object.
577575
@@ -1027,7 +1025,7 @@ def parse_spikeglx_snsGeomMap(meta):
10271025
# parse_spikeglx_snsGeomMap(meta)
10281026

10291027

1030-
def get_saved_channel_indices_from_spikeglx_meta(meta_file: str | Path) -> np.array:
1028+
def get_saved_channel_indices_from_spikeglx_meta(meta_file: str | Path) -> np.ndarray:
10311029
"""
10321030
Utils function to get the saved channels.
10331031
@@ -1067,7 +1065,7 @@ def _parse_openephys_settings(
10671065
settings_file: str | Path,
10681066
fix_x_position_for_oe_5: bool = True,
10691067
raise_error: bool = True,
1070-
) -> Optional[list[dict]]:
1068+
) -> list[dict] | None:
10711069
"""
10721070
Parse an Open Ephys settings.xml and extract per-probe metadata.
10731071
@@ -1396,11 +1394,11 @@ def _parse_openephys_settings(
13961394

13971395
def _select_openephys_probe_info(
13981396
probes_info: list[dict],
1399-
stream_name: Optional[str] = None,
1400-
probe_name: Optional[str] = None,
1401-
serial_number: Optional[str] = None,
1397+
stream_name: str | None = None,
1398+
probe_name: str | None = None,
1399+
serial_number: str | None = None,
14021400
raise_error: bool = True,
1403-
) -> Optional[dict]:
1401+
) -> dict | None:
14041402
"""
14051403
Select one probe's info dict from the list returned by `_parse_openephys_settings`.
14061404
@@ -1587,9 +1585,9 @@ def _annotate_openephys_probe(probe: Probe, probe_info: dict) -> None:
15871585

15881586
def read_openephys(
15891587
settings_file: str | Path,
1590-
stream_name: Optional[str] = None,
1591-
probe_name: Optional[str] = None,
1592-
serial_number: Optional[str] = None,
1588+
stream_name: str | None = None,
1589+
probe_name: str | None = None,
1590+
serial_number: str | None = None,
15931591
fix_x_position_for_oe_5: bool = True,
15941592
raise_error: bool = True,
15951593
) -> Probe:
@@ -1676,9 +1674,7 @@ def read_openephys(
16761674
return probe
16771675

16781676

1679-
def get_saved_channel_indices_from_openephys_settings(
1680-
settings_file: str | Path, stream_name: str
1681-
) -> Optional[np.array]:
1677+
def get_saved_channel_indices_from_openephys_settings(settings_file: str | Path, stream_name: str) -> np.ndarray | None:
16821678
"""
16831679
Returns an array with the subset of saved channels indices (if used)
16841680

src/probeinterface/plotting.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Depending on Probe.ndim, the plotting is done in 2D or 3D
66
"""
77

8-
from __future__ import annotations
8+
import warnings
99
import numpy as np
1010
from matplotlib import path as mpl_path
1111

@@ -46,8 +46,6 @@ def create_probe_polygons(
4646
The polygon collection for the probe shape
4747
"""
4848
if contacts_kargs is not None:
49-
import warnings
50-
5149
warnings.warn(
5250
"contacts_kargs is deprecated and will be removed in 0.3.4. Please use `contacts_kwargs` instead.",
5351
category=DeprecationWarning,
@@ -107,13 +105,14 @@ def plot_probe(
107105
contacts_values: list | np.ndarray | None = None,
108106
cmap: str = "viridis",
109107
title: bool = True,
110-
contacts_kargs: dict = {},
108+
contact_kwargs: dict = {},
111109
probe_shape_kwargs: dict = {},
112110
xlims: tuple | None = None,
113111
ylims: tuple | None = None,
114112
zlims: tuple | None = None,
115113
show_channel_on_click: bool = False,
116-
side=None,
114+
side: str | None = None,
115+
contacts_kargs: dict | None = None,
117116
):
118117
"""Plot a Probe object.
119118
Generates a 2D or 3D axis, depending on Probe.ndim
@@ -138,7 +137,7 @@ def plot_probe(
138137
A colormap color
139138
title : bool, default: True
140139
If True, the axis title is set to the probe name
141-
contacts_kargs : dict, default: {}
140+
contact_kwargs : dict, default: {}
142141
Dict with kwargs for contacts (e.g. alpha, edgecolor, lw)
143142
probe_shape_kwargs : dict, default: {}
144143
Dict with kwargs for probe shape (e.g. alpha, edgecolor, lw)
@@ -152,6 +151,8 @@ def plot_probe(
152151
If True, the channel information is shown upon click
153152
side : None | "front" | "back"
154153
If the probe is two side, then the side must be given otherwise this raises an error.
154+
contacts_kargs : dict | None, default: None
155+
DEPRECATED, use contact_kwargs instead. Dict with kwargs for contacts (e.g. alpha, edgecolor, lw)
155156
156157
Returns
157158
-------
@@ -162,6 +163,14 @@ def plot_probe(
162163
"""
163164
import matplotlib.pyplot as plt
164165

166+
if contacts_kargs is not None:
167+
warnings.warn(
168+
"contacts_kwargs is deprecated and will be removed in 0.3.4. Please use `contact_kwargs` instead.",
169+
category=DeprecationWarning,
170+
stacklevel=2,
171+
)
172+
contact_kwargs = contacts_kargs
173+
165174
if probe.contact_sides is not None:
166175
if side is None or side not in ("front", "back"):
167176
raise ValueError(
@@ -187,7 +196,7 @@ def plot_probe(
187196
contacts_colors=contacts_colors,
188197
contacts_values=contacts_values,
189198
cmap=cmap,
190-
contacts_kargs=contacts_kargs,
199+
contact_kwargs=contact_kwargs,
191200
probe_shape_kwargs=probe_shape_kwargs,
192201
)
193202

0 commit comments

Comments
 (0)