-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add type stubs to scipy/signal/_peak_finding.pyi
#87
Changes from 12 commits
d5c528b
c7733bc
88ea09c
d53d739
731c4d4
b453d06
d88bb48
13d8de6
73711bc
77c6017
cfbae52
2266ca0
beda31b
85f19ce
17930b7
d7b9cbd
5e1d325
09b3644
28fad98
11fa2aa
bb24cad
9f1ca74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,86 @@ | ||
from scipy._typing import Untyped | ||
from collections.abc import Callable, Sequence | ||
from typing import Concatenate, Literal, TypeAlias, TypedDict | ||
|
||
import numpy as np | ||
import numpy.typing as npt | ||
import optype as op | ||
from numpy._typing import _ArrayLikeInt_co | ||
from scipy._typing import AnyInt, AnyReal | ||
|
||
__all__ = ["argrelextrema", "argrelmax", "argrelmin", "find_peaks", "find_peaks_cwt", "peak_prominences", "peak_widths"] | ||
|
||
def argrelmin(data: Untyped, axis: int = 0, order: int = 1, mode: str = "clip") -> Untyped: ... | ||
def argrelmax(data: Untyped, axis: int = 0, order: int = 1, mode: str = "clip") -> Untyped: ... | ||
def argrelextrema(data: Untyped, comparator: Untyped, axis: int = 0, order: int = 1, mode: str = "clip") -> Untyped: ... | ||
def peak_prominences(x: Untyped, peaks: Untyped, wlen: Untyped | None = None) -> Untyped: ... | ||
_Array_n: TypeAlias = npt.NDArray[np.intp] | ||
_Array_n_1d: TypeAlias = np.ndarray[tuple[int], np.dtype[np.intp]] | ||
_Array_f8: TypeAlias = npt.NDArray[np.float64] | ||
_Mode: TypeAlias = Literal["clip", "wrap"] | ||
|
||
_ProminencesResult: TypeAlias = tuple[_Array_f8, _Array_n, _Array_n] | ||
_WidthsResult: TypeAlias = tuple[_Array_f8, _Array_f8, _Array_f8, _Array_f8] | ||
|
||
class _FindPeaksResultsDict(TypedDict, total=False): | ||
peak_heights: _Array_f8 | ||
left_thresholds: _Array_f8 | ||
right_thresholds: _Array_f8 | ||
prominences: _Array_f8 | ||
left_bases: _Array_n | ||
right_bases: _Array_n | ||
width_heights: _Array_f8 | ||
left_ips: _Array_f8 | ||
right_ips: _Array_f8 | ||
plateau_sizes: _Array_n | ||
left_edges: _Array_n | ||
right_edges: _Array_n | ||
|
||
def argrelmin( | ||
data: npt.NDArray[np.generic], | ||
axis: op.CanIndex = 0, | ||
order: int = 1, | ||
mode: _Mode = "clip", | ||
) -> tuple[_Array_n, ...]: ... | ||
def argrelmax( | ||
data: npt.NDArray[np.generic], | ||
axis: op.CanIndex = 0, | ||
order: int = 1, | ||
mode: _Mode = "clip", | ||
) -> tuple[_Array_n, ...]: ... | ||
def argrelextrema( | ||
data: npt.NDArray[np.generic], | ||
comparator: Callable[[npt.NDArray[np.generic], npt.NDArray[np.generic]], npt.NDArray[np.bool_]], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. totally optional; but you could use a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't that require the comparator function to have two arguments of the same type? I think that in the ideal case the function signature makes sense but what if someone were to pass a function that takes in a float and an int? They would still be able to do the comparison despite the types being different. Assuming that using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes exactly.
If someone would pass a function that accepts arrays whose scalar types are incompatible, then it would indeed not be allowed.
Well, it kinda depends on what you mean with "the same". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah got it. Just misunderstood the semantics. I can add this then. |
||
axis: op.CanIndex = 0, | ||
order: int = 1, | ||
mode: _Mode = "clip", | ||
) -> tuple[_Array_n, ...]: ... | ||
def peak_prominences( | ||
x: npt.ArrayLike, | ||
peaks: _ArrayLikeInt_co, | ||
wlen: AnyReal | None = None, | ||
) -> _ProminencesResult: ... | ||
def peak_widths( | ||
x: Untyped, | ||
peaks: Untyped, | ||
rel_height: float = 0.5, | ||
prominence_data: Untyped | None = None, | ||
wlen: Untyped | None = None, | ||
) -> Untyped: ... | ||
x: npt.ArrayLike, | ||
peaks: _ArrayLikeInt_co, | ||
rel_height: AnyReal = 0.5, | ||
prominence_data: _ProminencesResult | None = None, | ||
wlen: AnyReal | None = None, | ||
) -> _WidthsResult: ... | ||
def find_peaks( | ||
x: Untyped, | ||
height: Untyped | None = None, | ||
threshold: Untyped | None = None, | ||
distance: Untyped | None = None, | ||
prominence: Untyped | None = None, | ||
width: Untyped | None = None, | ||
wlen: Untyped | None = None, | ||
rel_height: float = 0.5, | ||
plateau_size: Untyped | None = None, | ||
) -> Untyped: ... | ||
x: npt.ArrayLike, | ||
height: AnyReal | _Array_f8 | tuple[AnyReal | None, AnyReal | None] | None = None, | ||
threshold: AnyReal | _Array_f8 | tuple[AnyReal | None, AnyReal | None] | None = None, | ||
distance: AnyReal | None = None, | ||
prominence: AnyReal | _Array_f8 | tuple[AnyReal | None, AnyReal | None] | None = None, | ||
width: AnyReal | _Array_f8 | tuple[AnyReal | None, AnyReal | None] | None = None, | ||
wlen: AnyReal | None = None, | ||
rel_height: AnyReal = 0.5, | ||
plateau_size: AnyInt | _Array_n | tuple[AnyInt | None, AnyInt | None] | None = None, | ||
) -> tuple[_Array_n, _FindPeaksResultsDict]: ... | ||
def find_peaks_cwt( | ||
vector: Untyped, | ||
widths: Untyped, | ||
wavelet: Untyped | None = None, | ||
max_distances: Untyped | None = None, | ||
gap_thresh: Untyped | None = None, | ||
min_length: Untyped | None = None, | ||
min_snr: int = 1, | ||
noise_perc: int = 10, | ||
window_size: Untyped | None = None, | ||
) -> Untyped: ... | ||
vector: npt.ArrayLike, | ||
widths: npt.ArrayLike, | ||
wavelet: Callable[Concatenate[int, float, ...], npt.ArrayLike] | None = None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my other comment on this signature |
||
max_distances: Sequence[int] | None = None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know it's a bit weird, but an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh thats a bit weird/annoying. The reason why I chose The source code for that function only calls Would the type then be like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem with And yea I agree that |
||
gap_thresh: AnyInt | None = None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could also be a float, according to the docs |
||
min_length: AnyInt | None = None, | ||
min_snr: AnyReal = 1, | ||
noise_perc: AnyReal = 10, | ||
window_size: AnyInt | None = None, | ||
) -> _Array_n_1d: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that besides
int
, you could also pass somenp.integer[Any]
andnp.bool_
toorder
. And coincidentally,scipy._typing.AnyInt
is an alias for exactly that :)There's also some other
order
s like this below