diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 36ff5d392a..5553fa411c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,7 +14,7 @@ repos: - id: ruff name: ruff language: python - types: [python] + types: [python, pyi] entry: ruff args: - --fix @@ -22,5 +22,5 @@ repos: - id: mypy name: mypy language: python - types: [python] + types: [python, pyi] entry: mypy --implicit-optional diff --git a/pyproject.toml b/pyproject.toml index b45f37e632..8986449f1f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -130,7 +130,6 @@ files = "river" [[tool.mypy.overrides]] module = [ - "river.*", "mmh3.*", "numpy.*", "sklearn.*", diff --git a/river/drift/adwin_c.pyi b/river/drift/adwin_c.pyi new file mode 100644 index 0000000000..75b5ad40f5 --- /dev/null +++ b/river/drift/adwin_c.pyi @@ -0,0 +1,27 @@ +class AdaptiveWindowing: + def __init__( + self, + delta: float = 0.002, + clock: int = 32, + max_buckets: int = 5, + min_window_length: int = 5, + grace_period: int = 10, + ) -> None: ... + def get_n_detections(self) -> int: ... + def get_width(self) -> float: ... + def get_total(self) -> float: ... + def get_variance(self) -> float: ... + @property + def variance_in_window(self) -> float: ... + def update(self, value: float) -> bool: ... + +class Bucket: + def __init__(self, max_size: int) -> None: ... + def clear_at(self, index: int) -> None: ... + def insert_data(self, value: float, variance: float) -> None: ... + def remove(self) -> None: ... + def compress(self, n_elements: int) -> None: ... + def get_total_at(self, index: int) -> float: ... + def get_variance_at(self, index: int) -> float: ... + def set_total_at(self, value: float, index: int) -> None: ... + def set_variance_at(self, value: float, index: int) -> None: ... diff --git a/river/metrics/efficient_rollingrocauc/efficient_rollingrocauc.pyi b/river/metrics/efficient_rollingrocauc/efficient_rollingrocauc.pyi new file mode 100644 index 0000000000..943d1fa6e4 --- /dev/null +++ b/river/metrics/efficient_rollingrocauc/efficient_rollingrocauc.pyi @@ -0,0 +1,12 @@ +from collections.abc import Sequence +from typing import Any + +class EfficientRollingROCAUC: + def __cinit__(self, positiveLabel: int, windowSize: int) -> None: ... + def __dealloc__(self) -> None: ... + def update(self, label: bool, score: bool | float | dict[bool, float]) -> None: ... + def revert(self, label: bool, score: bool | float | dict[bool, float]) -> None: ... + def get(self) -> float: ... + def __getnewargs_ex__(self) -> tuple[tuple[int, int], dict[str, Any]]: ... + def __getstate__(self) -> tuple[Sequence[int], Sequence[float]]: ... + def __setstate__(self, state: tuple[Sequence[int], Sequence[float]]) -> None: ... diff --git a/river/metrics/expected_mutual_info.pyi b/river/metrics/expected_mutual_info.pyi new file mode 100644 index 0000000000..f3b584f2d5 --- /dev/null +++ b/river/metrics/expected_mutual_info.pyi @@ -0,0 +1,3 @@ +from river import metrics + +def expected_mutual_info(confusion_matrix: metrics.ConfusionMatrix) -> float: ... diff --git a/river/utils/vectordict.pyi b/river/utils/vectordict.pyi new file mode 100644 index 0000000000..faa8086966 --- /dev/null +++ b/river/utils/vectordict.pyi @@ -0,0 +1,56 @@ +from collections.abc import Callable + +import numpy + +def get_union_keys(left: VectorDict, right: VectorDict): ... +def get_intersection_keys(left: VectorDict, right: VectorDict): ... + +class VectorDict: + def __init__( + self, + data: VectorDict | dict | None = None, + default_factory: Callable | None = None, + mask: VectorDict | set | None = None, + copy: bool = False, + ) -> None: ... + def with_mask(self, mask, copy=False): ... + def to_dict(self): ... + def to_numpy(self, fields) -> numpy.ndarray: ... + def __contains__(self, key): ... + def __delitem__(self, key): ... + def __format__(self, format_spec): ... + def __getitem__(self, key): ... + def __iter__(self): ... + def __len__(self): ... + def __repr__(self): ... + def __setitem__(self, key, value): ... + def __str__(self): ... + def clear(self): ... + def get(self, key, *args, **kwargs): ... + def items(self): ... + def keys(self): ... + def pop(self, *args, **kwargs): ... + def popitem(self): ... + def setdefault(self, key, *args, **kwargs): ... + def update(self, *args, **kwargs): ... + def values(self): ... + def __eq__(left, right): ... + def __add__(left, right): ... + def __iadd__(self, other): ... + def __sub__(left, right): ... + def __isub__(self, other): ... + def __mul__(left, right): ... + def __imul__(self, other): ... + def __truediv__(left, right): ... + def __itruediv__(self, other): ... + def __pow__(left, right): ... + def __ipow__(self, other): ... + def __matmul__(left, right): ... + def __neg__(self): ... + def __pos__(self): ... + def __abs__(self): ... + def abs(self): ... + def min(self): ... + def max(self): ... + def minimum(self, other): ... + def maximum(self, other): ... diff --git a/river/utils/vectordict.pyx b/river/utils/vectordict.pyx index 3ef20817fc..00d8c1911d 100644 --- a/river/utils/vectordict.pyx +++ b/river/utils/vectordict.pyx @@ -427,8 +427,8 @@ cdef class VectorDict: return NotImplemented return self - def __pow__(left, right, modulo): - if not isinstance(left, VectorDict) or modulo is not None: + def __pow__(left, right): + if not isinstance(left, VectorDict): return NotImplemented left_ = left res = left_._to_dict(force_copy=True)