Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions stubs/resampy/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
resampy.interpn.resample_f_p
resampy.interpn.resample_f_s
Comment on lines +1 to +2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add an explanatory comment to these entries?
I don’t claim to fully understand how this works in practice, but from what I’ve seen in the calls to these functions within the library, it seems the following:

Suggested change
resampy.interpn.resample_f_p
resampy.interpn.resample_f_s
# @numba.guvectorize creates np.ufunc objects, but these functions still have the same signatures
resampy.interpn.resample_f_p
resampy.interpn.resample_f_s

4 changes: 4 additions & 0 deletions stubs/resampy/METADATA.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version = "0.4.*"
upstream_repository = "https://github.com/bmcfee/resampy"
# Requires a version of numpy with a `py.typed` file
requires = ["numpy>=1.20"]
2 changes: 2 additions & 0 deletions stubs/resampy/resampy/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import filters as filters
from .core import *
29 changes: 29 additions & 0 deletions stubs/resampy/resampy/core.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from collections.abc import Callable
from typing import Any
from typing_extensions import TypeAlias, TypeVar

import numpy as np

__all__ = ["resample", "resample_nu"]

_FloatArray = TypeVar("_FloatArray", bound=np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]])
_FilterType: TypeAlias = str | Callable[..., tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], int, float]]
Comment on lines +9 to +10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type passed to generic np.floating is responsible for precision, which by default already has the value Any (and this is rarely necessary), so you can get rid of all these Any:

Suggested change
_FloatArray = TypeVar("_FloatArray", bound=np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]])
_FilterType: TypeAlias = str | Callable[..., tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], int, float]]
_FloatArray = TypeVar("_FloatArray", bound=np.ndarray[tuple[int, ...], np.dtype[np.floating]])
_FilterType: TypeAlias = str | Callable[..., tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating]], int, float]]


def resample(
x: _FloatArray,
sr_orig: float,
sr_new: float,
axis: int = -1,
filter: _FilterType = "kaiser_best",
parallel: bool = False,
**kwargs: Any,
) -> _FloatArray: ...
def resample_nu(
x: _FloatArray,
sr_orig: float,
t_out: _FloatArray,
axis: int = -1,
filter: _FilterType = "kaiser_best",
parallel: bool = False,
**kwargs: Any,
Comment on lines +19 to +28
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typeshed expects that Any types have comment with explanation on why Any was used or what types are allowed, especially important for **kwargs: Any.
You can leave them unannotated, but then be sure to add resampy path(s) to the exclude list:

Suggested change
**kwargs: Any,
) -> _FloatArray: ...
def resample_nu(
x: _FloatArray,
sr_orig: float,
t_out: _FloatArray,
axis: int = -1,
filter: _FilterType = "kaiser_best",
parallel: bool = False,
**kwargs: Any,
**kwargs,
) -> _FloatArray: ...
def resample_nu(
x: _FloatArray,
sr_orig: float,
t_out: _FloatArray,
axis: int = -1,
filter: _FilterType = "kaiser_best",
parallel: bool = False,
**kwargs,

) -> _FloatArray: ...
25 changes: 25 additions & 0 deletions stubs/resampy/resampy/filters.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from collections.abc import Callable
from typing import Any

import numpy as np

__all__ = ["get_filter", "clear_cache", "sinc_window"]

# Dictionary to cache loaded filters
FILTER_CACHE: dict[str, tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], int, float]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
FILTER_CACHE: dict[str, tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], int, float]]
FILTER_CACHE: dict[str, tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating]], int, float]]


# List of filter functions available
FILTER_FUNCTIONS: list[str]

def sinc_window(
num_zeros: int = 64,
precision: int = 9,
window: Callable[..., np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]]] | None = None,
rolloff: float = 0.945,
) -> tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], int, float]: ...
def get_filter(
name_or_function: str | Callable[..., tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], int, float]],
**kwargs: Any,
) -> tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], int, float]: ...
def load_filter(filter_name: str) -> tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], int, float]: ...
def clear_cache() -> None: ...
Comment on lines +9 to +25
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here:

Suggested change
FILTER_CACHE: dict[str, tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], int, float]]
# List of filter functions available
FILTER_FUNCTIONS: list[str]
def sinc_window(
num_zeros: int = 64,
precision: int = 9,
window: Callable[..., np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]]] | None = None,
rolloff: float = 0.945,
) -> tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], int, float]: ...
def get_filter(
name_or_function: str | Callable[..., tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], int, float]],
**kwargs: Any,
) -> tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], int, float]: ...
def load_filter(filter_name: str) -> tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], int, float]: ...
def clear_cache() -> None: ...
FILTER_CACHE: dict[str, tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating]], int, float]]
# List of filter functions available
FILTER_FUNCTIONS: list[str]
def sinc_window(
num_zeros: int = 64,
precision: int = 9,
window: Callable[..., np.ndarray[tuple[int, ...], np.dtype[np.floating]]] | None = None,
rolloff: float = 0.945,
) -> tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating]], int, float]: ...
def get_filter(
name_or_function: str | Callable[..., tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating]], int, float]],
**kwargs,
) -> tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating]], int, float]: ...
def load_filter(filter_name: str) -> tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating]], int, float]: ...
def clear_cache() -> None: ...

38 changes: 38 additions & 0 deletions stubs/resampy/resampy/interpn.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from typing import Any

import numpy as np

def _resample_loop(
x: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]],
t_out: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]],
interp_win: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]],
interp_delta: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]],
num_table: int,
scale: float,
y: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]],
) -> None: ...
Comment on lines +5 to +13
Copy link
Contributor

@donbarbos donbarbos Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

Suggested change
def _resample_loop(
x: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]],
t_out: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]],
interp_win: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]],
interp_delta: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]],
num_table: int,
scale: float,
y: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]],
) -> None: ...
def _resample_loop(
x: np.ndarray[tuple[int, ...], np.dtype[np.floating]],
t_out: np.ndarray[tuple[int, ...], np.dtype[np.floating]],
interp_win: np.ndarray[tuple[int, ...], np.dtype[np.floating]],
interp_delta: np.ndarray[tuple[int, ...], np.dtype[np.floating]],
num_table: int,
scale: float,
y: np.ndarray[tuple[int, ...], np.dtype[np.floating]],
) -> None: ...


# JIT-compiled parallel version of _resample_loop
_resample_loop_p = ...

# JIT-compiled sequential version of _resample_loop
_resample_loop_s = ...

Comment on lines +14 to +20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like internal API, so I suggest removing it, especially if you don't add types to it (this may also apply to _resample_loop)

Suggested change
# JIT-compiled parallel version of _resample_loop
_resample_loop_p = ...
# JIT-compiled sequential version of _resample_loop
_resample_loop_s = ...

or if you are sure about types and consider it necessary, you can specify them something like this:

Suggested change
# JIT-compiled parallel version of _resample_loop
_resample_loop_p = ...
# JIT-compiled sequential version of _resample_loop
_resample_loop_s = ...
_resample_loop_p = _resample_loop
_resample_loop_s = _resample_loop

def resample_f_p(
x: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]],
t_out: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]],
interp_win: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]],
interp_delta: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]],
num_table: int,
scale: float,
y: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]],
) -> None: ...
def resample_f_s(
x: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]],
t_out: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]],
interp_win: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]],
interp_delta: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]],
num_table: int,
scale: float,
y: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]],
) -> None: ...
Comment on lines +21 to +38
Copy link
Contributor

@donbarbos donbarbos Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

Suggested change
def resample_f_p(
x: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]],
t_out: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]],
interp_win: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]],
interp_delta: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]],
num_table: int,
scale: float,
y: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]],
) -> None: ...
def resample_f_s(
x: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]],
t_out: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]],
interp_win: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]],
interp_delta: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]],
num_table: int,
scale: float,
y: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]],
) -> None: ...
def resample_f_p(
x: np.ndarray[tuple[int, ...], np.dtype[np.floating]],
t_out: np.ndarray[tuple[int, ...], np.dtype[np.floating]],
interp_win: np.ndarray[tuple[int, ...], np.dtype[np.floating]],
interp_delta: np.ndarray[tuple[int, ...], np.dtype[np.floating]],
num_table: int,
scale: float,
y: np.ndarray[tuple[int, ...], np.dtype[np.floating]],
) -> None: ...
def resample_f_s(
x: np.ndarray[tuple[int, ...], np.dtype[np.floating]],
t_out: np.ndarray[tuple[int, ...], np.dtype[np.floating]],
interp_win: np.ndarray[tuple[int, ...], np.dtype[np.floating]],
interp_delta: np.ndarray[tuple[int, ...], np.dtype[np.floating]],
num_table: int,
scale: float,
y: np.ndarray[tuple[int, ...], np.dtype[np.floating]],
) -> None: ...

4 changes: 4 additions & 0 deletions stubs/resampy/resampy/version.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from typing import Final

short_version: Final[str]
version: Final[str]