Skip to content

Commit ac238b6

Browse files
committed
Fixed missing parameter definitions in docstrings
1 parent 8da71ec commit ac238b6

File tree

12 files changed

+126
-32
lines changed

12 files changed

+126
-32
lines changed

docstring.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env python
2+
3+
import pathlib
4+
import ast
5+
import re
6+
7+
8+
def get_docstring_args(docstring):
9+
"""
10+
Extract parameter arguments from docstring
11+
"""
12+
args = re.findall(r"(\w+)\s+\:", docstring)
13+
args = [a for a in args if a != "self"]
14+
return args
15+
16+
17+
ignore = ["__init__.py", "__pycache__"]
18+
19+
stumpy_path = pathlib.Path(__file__).parent / "stumpy"
20+
filepaths = sorted(f for f in pathlib.Path(stumpy_path).iterdir() if f.is_file())
21+
for filepath in filepaths:
22+
if filepath.name not in ignore and str(filepath).endswith(".py"):
23+
file_contents = ""
24+
with open(filepath, encoding="utf8") as f:
25+
file_contents = f.read()
26+
module = ast.parse(file_contents)
27+
28+
# Check Functions
29+
function_definitions = [
30+
node for node in module.body if isinstance(node, ast.FunctionDef)
31+
]
32+
for fd in function_definitions:
33+
docstring_args = set(get_docstring_args(ast.get_docstring(fd)))
34+
signature_args = set([a.arg for a in fd.args.args])
35+
diff_args = signature_args.difference(docstring_args)
36+
if len(diff_args) > 0:
37+
print("Found one or more parameters with missing docstring:")
38+
print(f" File: {filepath.name}")
39+
print(f" Function: {fd.name}")
40+
print(f" Parameters: {diff_args}")
41+
# print(ast.get_docstring(fd))
42+
# print(docstring_args)
43+
# print(signature_args)
44+
45+
# Check Class Methods
46+
class_definitions = [
47+
node for node in module.body if isinstance(node, ast.ClassDef)
48+
]
49+
for cd in class_definitions:
50+
methods = [node for node in cd.body if isinstance(node, ast.FunctionDef)]
51+
for fd in methods:
52+
docstring_args = set(get_docstring_args(ast.get_docstring(fd)))
53+
signature_args = set([a.arg for a in fd.args.args if a.arg != "self"])
54+
diff_args = signature_args.difference(docstring_args)
55+
if len(diff_args) > 0:
56+
print("Found one or more parameters with missing docstring:")
57+
print(f" File: {filepath.name}")
58+
print(f" Class: {cd.name}")
59+
print(f" Method: {fd.name}")
60+
print(f" Parameters: {diff_args}")
61+
# print(ast.get_docstring(fd))
62+
# print(docstring_args)
63+
# print(signature_args)

stumpy/aamp_mmotifs.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,70 +33,70 @@ def aamp_mmotifs(
3333
3434
Parameters
3535
----------
36-
T: numpy.ndarray
36+
T : numpy.ndarray
3737
The multi-dimensional time series or sequence
3838
39-
P: numpy.ndarray
39+
P : numpy.ndarray
4040
Multi-dimensional Matrix Profile of T
4141
42-
I: numpy.ndarray
42+
I : numpy.ndarray
4343
Multi-dimensional Matrix Profile indices
4444
4545
min_neighbors : int, default 1
4646
The minimum number of similar matches a subsequence needs to have in order
4747
to be considered a motif. This defaults to `1`, which means that a subsequence
4848
must have at least one similar match in order to be considered a motif.
4949
50-
max_distance: flaot, default None
50+
max_distance : flaot, default None
5151
Maximal distance that is allowed between a query subsequence
5252
(a candidate motif) and all subsequences in T to be considered as a match.
5353
If None, this defaults to
5454
`np.nanmax([np.nanmean(D) - 2 * np.nanstd(D), np.nanmin(D)])`
5555
(i.e. at least the closest match will be returned).
5656
57-
cutoffs: numpy.ndarray or float, default None
57+
cutoffs : numpy.ndarray or float, default None
5858
The largest matrix profile value (distance) for each dimension of the
5959
multidimensional matrix profile that a multidimenisonal candidate motif is
6060
allowed to have. If `cutoffs` is a scalar value, then this value will be
6161
applied to every dimension.
6262
63-
max_matches: int, default 10
63+
max_matches : int, default 10
6464
The maximum number of similar matches (nearest neighbors) to return for each
6565
motif. The first match is always the self/trivial-match for each motif.
6666
67-
max_motifs: int, default 1
67+
max_motifs : int, default 1
6868
The maximum number of motifs to return
6969
70-
atol: float, default 1e-8
70+
atol : float, default 1e-8
7171
The absolute tolerance parameter. This value will be added to `max_distance`
7272
when comparing distances between subsequences.
7373
74-
k: int, default None
74+
k : int, default None
7575
The number of dimensions (`k + 1`) required for discovering all motifs. This
7676
value is available for doing guided search or, together with `include`, for
7777
constrained search. If `k is None`, then this will be automatically be computed
7878
for each motif using MDL (unconstrained search).
7979
80-
include: numpy.ndarray, default None
80+
include : numpy.ndarray, default None
8181
A list of (zero based) indices corresponding to the dimensions in T that must be
8282
included in the constrained multidimensional motif search.
8383
84-
p: float, default 2.0
84+
p : float, default 2.0
8585
The p-norm to apply for computing the Minkowski distance.
8686
8787
Returns
8888
-------
89-
motif_distances: numpy.ndarray
89+
motif_distances : numpy.ndarray
9090
The distances corresponding to a set of subsequence matches for each motif.
9191
92-
motif_indices: numpy.ndarray
92+
motif_indices : numpy.ndarray
9393
The indices corresponding to a set of subsequences matches for each motif.
9494
95-
motif_subspaces: list
95+
motif_subspaces : list
9696
A list consisting of arrays that contain the `k`-dimensional
9797
subspace for each motif.
9898
99-
motif_mdls: list
99+
motif_mdls : list
100100
A list consisting of arrays that contain the mdl results for
101101
finding the dimension of each motif
102102

stumpy/aamp_stimp.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,9 @@ def __init__(
550550
551551
step : int, default 1
552552
The step between subsequence window sizes
553+
554+
p : float, default 2.0
555+
The p-norm to apply for computing the Minkowski distance.
553556
"""
554557
super().__init__(
555558
T,

stumpy/aampi.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ def _update_egress(self, t):
168168
"""
169169
Ingress a new data point, egress the oldest data point, and update the matrix
170170
profile and matrix profile indices
171+
172+
Parameters
173+
----------
174+
t : float
175+
A single new data point to be appended to `T`
171176
"""
172177
self._n = self._T.shape[0]
173178
l = self._n - self._m + 1 - 1 # Subtract 1 due to egress
@@ -245,6 +250,11 @@ def _update(self, t):
245250
"""
246251
Ingress a new data point and update the (top-k) matrix profile and matrix
247252
profile indices without egressing the oldest data point
253+
254+
Parameters
255+
----------
256+
t : float
257+
A single new data point to be appended to `T`
248258
"""
249259
self._n = self._T.shape[0]
250260
l = self._n - self._m + 1

stumpy/core.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2750,19 +2750,19 @@ def _shift_insert_at_index(a, idx, v, shift="right"):
27502750
27512751
Parameters
27522752
----------
2753-
a: numpy.ndarray
2753+
a : numpy.ndarray
27542754
A 1d array
27552755
2756-
idx: int
2756+
idx : int
27572757
The index at which the value `v` should be inserted. This can be any
27582758
integer number from `0` to `len(a)`. When `idx=len(a)` and `shift="right"`,
27592759
OR when `idx=0` and `shift="left"`, then no change will occur on
27602760
the input array `a`.
27612761
2762-
v: float
2762+
v : float
27632763
The value that should be inserted into array `a` at index `idx`
27642764
2765-
shift: str, default "right"
2765+
shift : str, default "right"
27662766
The value that indicates whether the shifting of elements should be towards
27672767
the right or left. If `shift="right"` (default), all elements in `a[idx:]`
27682768
are shifted to the right by one element. If `shift="left"`, all elements

stumpy/gpu_aamp.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ def _compute_and_update_PI_kernel(
115115
compute_p_norm : bool
116116
A boolean flag for whether or not to compute the p-norm
117117
118+
bfs : numpy.ndarray
119+
The breadth-first-search indices where the missing leaves of its corresponding
120+
binary search tree are filled with -1.
121+
122+
nlevel : int
123+
The number of levels in the binary search tree from which the array
124+
`bfs` is obtained.
125+
118126
k : int
119127
The number of top `k` smallest distances used to construct the matrix profile.
120128
Note that this will increase the total computational time and memory usage

stumpy/maamp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ def _maamp(
721721
722722
Parameters
723723
----------
724-
T: numpy.ndarray
724+
T : numpy.ndarray
725725
The time series or sequence for which to compute the multi-dimensional
726726
matrix profile
727727

stumpy/mmotifs.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,51 +33,51 @@ def mmotifs(
3333
3434
Parameters
3535
----------
36-
T: numpy.ndarray
36+
T : numpy.ndarray
3737
The multi-dimensional time series or sequence
3838
39-
P: numpy.ndarray
39+
P : numpy.ndarray
4040
Multi-dimensional Matrix Profile of T
4141
42-
I: numpy.ndarray
42+
I : numpy.ndarray
4343
Multi-dimensional Matrix Profile indices
4444
4545
min_neighbors : int, default 1
4646
The minimum number of similar matches a subsequence needs to have in order
4747
to be considered a motif. This defaults to `1`, which means that a subsequence
4848
must have at least one similar match in order to be considered a motif.
4949
50-
max_distance: flaot, default None
50+
max_distance : flaot, default None
5151
Maximal distance that is allowed between a query subsequence
5252
(a candidate motif) and all subsequences in T to be considered as a match.
5353
If None, this defaults to
5454
`np.nanmax([np.nanmean(D) - 2 * np.nanstd(D), np.nanmin(D)])`
5555
(i.e. at least the closest match will be returned).
5656
57-
cutoffs: numpy.ndarray or float, default None
57+
cutoffs : numpy.ndarray or float, default None
5858
The largest matrix profile value (distance) for each dimension of the
5959
multidimensional matrix profile that a multidimenisonal candidate motif is
6060
allowed to have. If `cutoffs` is a scalar value, then this value will be
6161
applied to every dimension.
6262
63-
max_matches: int, default 10
63+
max_matches : int, default 10
6464
The maximum number of similar matches (nearest neighbors) to return for each
6565
motif. The first match is always the self/trivial-match for each motif.
6666
67-
max_motifs: int, default 1
67+
max_motifs : int, default 1
6868
The maximum number of motifs to return
6969
7070
atol : float, default 1e-8
7171
The absolute tolerance parameter. This value will be added to `max_distance`
7272
when comparing distances between subsequences.
7373
74-
k: int, default None
74+
k : int, default None
7575
The number of dimensions (`k + 1`) required for discovering all motifs. This
7676
value is available for doing guided search or, together with `include`, for
7777
constrained search. If `k is None`, then this will be automatically be computed
7878
for each motif using MDL (unconstrained search).
7979
80-
include: numpy.ndarray, default None
80+
include : numpy.ndarray, default None
8181
A list of (zero based) indices corresponding to the dimensions in T that must be
8282
included in the constrained multidimensional motif search.
8383

stumpy/mstump.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ def _mstump(
10071007
10081008
Parameters
10091009
----------
1010-
T: numpy.ndarray
1010+
T : numpy.ndarray
10111011
The time series or sequence for which to compute the multi-dimensional
10121012
matrix profile
10131013

stumpy/scraamp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def _prescraamp(
331331
p : float, default 2.0
332332
The p-norm to apply for computing the Minkowski distance.
333333
334-
i : int
334+
indices : int
335335
The subsequence index in `T_B` that corresponds to `Q`
336336
337337
s : int

0 commit comments

Comments
 (0)