Skip to content

Commit 400469a

Browse files
committed
Add typing
1 parent 87885a0 commit 400469a

File tree

6 files changed

+78
-73
lines changed

6 files changed

+78
-73
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ jobs:
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
python-version: ["3.9", "3.10", "3.11"]
16-
mpl-version: ["3.7", "3.8", "latest"]
15+
python-version: ["3.10", "3.11", "3.12", "3.13"]
16+
mpl-version: ["3.9", "3.10", "latest"]
1717
steps:
1818
- name: Checkout
1919
uses: actions/checkout@v4

changelog.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Added
2222
- :func:`mplsignal.scipyplot.freqz_tristacked` for plotting magnitude, phase, and group
2323
delay in a single plot.
2424
- BREAKING: argument *align_ylabels* to all ``freq*``-plots which is ``True`` by default.
25+
- Initial typing information.
2526

2627
Changed
2728
^^^^^^^
@@ -31,6 +32,12 @@ Changed
3132
- BREAKING: All functions in :mod:`mplsignal.scipyplot` now use a constrained layout. This
3233
will in general make the plot clearer, although at the expense of margin.
3334

35+
Fixed
36+
^^^^^
37+
38+
- ``freq_unit`` was not propagated properly in all ``freq_plots.zfreq*`` functions and
39+
``style``-combinations.
40+
3441
[0.2.0] - 2023-03-05
3542
--------------------
3643

lib/mplsignal/freq_plots.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
"freqz_zpk",
1212
"freqz_fir",
1313
]
14+
from typing import Literal
15+
1416
import matplotlib.pyplot as plt
1517
import numpy as np
1618
from mplsignal import _api, _utils
@@ -28,18 +30,20 @@ def freqz(
2830
den=None,
2931
zeros=None,
3032
poles=None,
31-
gain=1.0,
33+
gain: float = 1.0,
3234
w=None,
33-
freq_unit='rad',
34-
phase_unit='rad',
35+
freq_unit: Literal['rad', 'deg', 'norm', 'fs', 'normfs'] = 'rad',
36+
phase_unit: Literal['rad', 'deg'] = 'rad',
3537
ax=None,
36-
style='stacked',
37-
magnitude_scale='log',
38-
frequency_scale='linear',
39-
whole=False,
40-
include_nyquist=False,
41-
fs=2 * np.pi,
42-
align_ylabels=True,
38+
style: Literal[
39+
'stacked', 'twin', 'magnitude', 'phase', 'group_delay', 'tristacked'
40+
] = 'stacked',
41+
magnitude_scale: Literal['log', 'linear'] = 'log',
42+
frequency_scale: Literal['log', 'linear'] = 'linear',
43+
whole: bool = False,
44+
include_nyquist: bool = False,
45+
fs: float = 2 * np.pi,
46+
align_ylabels: bool = True,
4347
**kwargs,
4448
):
4549
"""
@@ -225,6 +229,7 @@ def _plot_h(
225229
xmax=maxx,
226230
xlabel=(freqlabel if style == 'twin' else None),
227231
ylabel=maglabel,
232+
freq_unit=freq_unit,
228233
frequency_scale=frequency_scale,
229234
magnitude_scale=magnitude_scale,
230235
fs=fs,
@@ -245,6 +250,7 @@ def _plot_h(
245250
xmin=minx,
246251
xmax=maxx,
247252
phase_unit=phase_unit,
253+
freq_unit=freq_unit,
248254
ylabel=phaselabel,
249255
xlabel=(freqlabel if style == 'stacked' else None),
250256
fs=fs,

lib/mplsignal/plane_plots.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
]
1313

1414
import math
15+
from typing import Optional
1516

1617
import adjustText
1718
import matplotlib.pyplot as plt
@@ -23,16 +24,16 @@ def zplane(
2324
poles=None,
2425
ax=None,
2526
adjust=1,
26-
spinelinewidth=0.2,
27+
spinelinewidth: float = 0.2,
2728
spinecolor='black',
2829
zeromarker='o',
2930
polemarker='x',
30-
unitcircle=True,
31+
unitcircle: bool = True,
3132
markercolor=None,
3233
zerofillstyle='none',
3334
polefillstyle='none',
34-
reallabel=None,
35-
imaglabel=None,
35+
reallabel: Optional[str] = None,
36+
imaglabel: Optional[str] = None,
3637
zero_props=None,
3738
pole_props=None,
3839
multiplicity_props=None,

lib/mplsignal/ticker.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"""
88
import math
99
from fractions import Fraction
10+
from typing import Optional
1011

1112
from matplotlib.ticker import Formatter, Locator, MaxNLocator
1213

@@ -24,15 +25,15 @@ class FactorLocator(Locator):
2425
2526
Parameters
2627
----------
27-
factor : float
28+
factor : float, default: 1.0
2829
The factor to extract.
29-
nbins : int
30+
nbins : int, optional
3031
Number of bins to aim for, see :class:`~matplotlib.tickers.MaxNLocator`.
3132
**kwargs
3233
Additional arguments passed to :class:`~matplotlib.tickers.MaxNLocator`.
3334
"""
3435

35-
def __init__(self, factor=1.0, nbins=None, **kwargs):
36+
def __init__(self, factor: float = 1.0, nbins: Optional[int] = None, **kwargs):
3637
"""
3738
Locator for finding multiples of *factor*.
3839
"""
@@ -65,18 +66,18 @@ class PiLocator(FactorLocator):
6566
6667
Parameters
6768
----------
68-
nbins : int
69+
nbins : int, optional
6970
Number of bins to aim for, see :class:`~matplotlib.tickers.MaxNLocator`.
7071
"""
7172

72-
def __init__(self, nbins=None, **kwargs):
73+
def __init__(self, nbins: Optional[int] = None, **kwargs):
7374
super().__init__(factor=math.pi, nbins=nbins, **kwargs)
7475

7576

7677
class SampleFrequencyLocator(FactorLocator):
7778
"""Locator for finding multiples of sample frequency."""
7879

79-
def __init__(self, nbins=None, fs=1.0, **kwargs):
80+
def __init__(self, nbins: Optional[int] = None, fs: float = 1.0, **kwargs):
8081
super().__init__(factor=fs / (2 * math.pi), nbins=nbins, **kwargs)
8182

8283

@@ -86,11 +87,11 @@ class DegreeLocator(MaxNLocator):
8687
8788
Parameters
8889
----------
89-
nbins : int
90+
nbins : int, optional
9091
Number of bins to aim for, see :class:`~matplotlib.tickers.MaxNLocator`.
9192
"""
9293

93-
def __init__(self, nbins=None, **kwargs):
94+
def __init__(self, nbins: Optional[int] = None, **kwargs):
9495
steps = kwargs.pop('steps', [1, 1.5, 2, 3, 5, 6, 10])
9596
if nbins is None:
9697
nbins = 'auto'
@@ -121,7 +122,12 @@ class FactorFormatter(Formatter):
121122
locs = []
122123

123124
def __init__(
124-
self, digits=3, factor=1.0, name="constant", name_on_all_numbers=False, **kwargs
125+
self,
126+
digits: int = 3,
127+
factor: float = 1.0,
128+
name: str = "constant",
129+
name_on_all_numbers: bool = False,
130+
**kwargs,
125131
):
126132
self._digits = digits
127133
self._factor = factor
@@ -164,7 +170,7 @@ class PiFormatter(FactorFormatter):
164170
Cannot include *factor* and *name*.
165171
"""
166172

167-
def __init__(self, digits=3, **kwargs):
173+
def __init__(self, digits: int = 3, **kwargs):
168174
super().__init__(digits=digits, factor=math.pi, name=r"\pi", **kwargs)
169175

170176

@@ -183,7 +189,7 @@ class SampleFrequencyFormatter(FactorFormatter):
183189
Cannot include *factor* and *name*.
184190
"""
185191

186-
def __init__(self, digits=3, fs=1.0, **kwargs):
192+
def __init__(self, digits: int = 3, fs: float = 1.0, **kwargs):
187193
super().__init__(
188194
digits=digits, factor=fs / (2 * math.pi), name=r"f_s", **kwargs
189195
)
@@ -204,7 +210,7 @@ class DegreeFormatter(FactorFormatter):
204210
Cannot include *factor*, *name*, and *only_name_when_one*.
205211
"""
206212

207-
def __init__(self, digits=3, **kwargs):
213+
def __init__(self, digits: int = 3, **kwargs):
208214
super().__init__(
209215
digits=digits,
210216
factor=1,
@@ -233,7 +239,7 @@ class PiRationalFormatter(Formatter):
233239
# individual ones
234240
locs = []
235241

236-
def __init__(self, digits=3, pi_always_in_numerator=True, **kwargs):
242+
def __init__(self, digits: int = 3, pi_always_in_numerator: bool = True, **kwargs):
237243
self._digits = digits
238244
self._pi_always_in_numerator = pi_always_in_numerator
239245
super().__init__(**kwargs)

pyproject.toml

Lines changed: 29 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,40 @@
11
[project]
22
name = "mplsignal"
33
description = "Matplotlib extension for signal processing-related plots"
4-
authors = [
5-
{name = "Oscar Gustafsson", email = "oscar.gustafsson@gmail.com"}
6-
]
7-
requires-python = ">=3.8"
8-
license = {file = "LICENSE"}
4+
authors = [{ name = "Oscar Gustafsson", email = "oscar.gustafsson@gmail.com" }]
5+
requires-python = ">=3.10"
6+
license = { file = "LICENSE" }
97
readme = "README.md"
10-
dynamic = [
11-
"version"
12-
]
13-
dependencies = [
14-
"matplotlib",
15-
"adjustText"
16-
]
17-
8+
dynamic = ["version"]
9+
dependencies = ["matplotlib>=3.9", "adjustText"]
1810
classifiers = [
19-
"Development Status :: 3 - Alpha",
20-
"Framework :: Matplotlib",
21-
"Intended Audience :: Developers",
22-
"Intended Audience :: Science/Research",
23-
"License :: OSI Approved :: BSD License",
24-
"Programming Language :: Python",
25-
"Programming Language :: Python :: 3",
26-
"Programming Language :: Python :: 3.8",
27-
"Programming Language :: Python :: 3.9",
28-
"Programming Language :: Python :: 3.10",
29-
"Programming Language :: Python :: 3.11",
30-
'Topic :: Scientific/Engineering :: Visualization',
11+
"Development Status :: 3 - Alpha",
12+
"Framework :: Matplotlib",
13+
"Intended Audience :: Developers",
14+
"Intended Audience :: Science/Research",
15+
"License :: OSI Approved :: BSD License",
16+
"Programming Language :: Python",
17+
"Programming Language :: Python :: 3",
18+
"Programming Language :: Python :: 3.10",
19+
"Programming Language :: Python :: 3.11",
20+
"Programming Language :: Python :: 3.12",
21+
"Programming Language :: Python :: 3.13",
22+
'Topic :: Scientific/Engineering :: Visualization',
3123
]
3224

3325
[project.optional-dependencies]
34-
test = [
35-
"black",
36-
"pytest",
37-
"pytest-mpl",
38-
"pytest-cov"
39-
]
26+
test = ["black", "pytest", "pytest-mpl", "pytest-cov"]
4027
doc = [
41-
"sphinx",
42-
"numpydoc",
43-
"sphinx_rtd_theme",
44-
"sphinx-copybutton",
45-
"sphinx-autobuild",
46-
"sphinx_gallery>=0.8.2",
47-
"autoapi",
48-
"furo",
49-
"scipy"
50-
]
28+
"sphinx",
29+
"numpydoc",
30+
"sphinx_rtd_theme",
31+
"sphinx-copybutton",
32+
"sphinx-autobuild",
33+
"sphinx_gallery>=0.8.2",
34+
"autoapi",
35+
"furo",
36+
"scipy"
37+
]
5138

5239
[project.urls]
5340
Homepage = "https://github.com/oscargus/mplsignal"
@@ -79,9 +66,7 @@ skip-string-normalization = true
7966
line-length = 88
8067

8168
[tool.pytest.ini_options]
82-
testpaths = [
83-
"mplsignal/tests"
84-
]
69+
testpaths = ["mplsignal/tests"]
8570

8671
[tool.isort]
8772
profile = "black"

0 commit comments

Comments
 (0)