From c8282c46a5862bdf2744eb01c3d075f2a1351570 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20Royer?= Date: Fri, 16 Aug 2024 18:08:19 +0200 Subject: [PATCH 1/7] Check for missing imports in River --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) 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.*", From 64f479a5a0e67b68e1f7a9fac01fa610468d2ca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20Royer?= Date: Fri, 16 Aug 2024 18:34:11 +0200 Subject: [PATCH 2/7] Add type stubs for expected_mutual_info.pyx --- river/metrics/expected_mutual_info.pyi | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 river/metrics/expected_mutual_info.pyi 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: ... From 0f120328669bc7ddf9a33fb757a0e0e73aeffd88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20Royer?= Date: Fri, 16 Aug 2024 18:35:17 +0200 Subject: [PATCH 3/7] Add type stubs for efficient_rollingrocauc.pyx --- .../efficient_rollingrocauc.pyi | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 river/metrics/efficient_rollingrocauc/efficient_rollingrocauc.pyi 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: ... From a80f83784a918696d1a01ea12a375f16ccacb21a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20Royer?= Date: Thu, 22 Aug 2024 12:34:54 +0200 Subject: [PATCH 4/7] Add type stub for adwin_c --- river/drift/adwin_c.pyi | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 river/drift/adwin_c.pyi 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: ... From 4e69f44ba4b6330f4d3b7a756848683780b3173b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20Royer?= Date: Thu, 22 Aug 2024 12:36:39 +0200 Subject: [PATCH 5/7] Add basic type stubs for vectordict --- river/utils/vectordict.pyi | 56 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 river/utils/vectordict.pyi diff --git a/river/utils/vectordict.pyi b/river/utils/vectordict.pyi new file mode 100644 index 0000000000..395681a239 --- /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, modulo): ... + 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): ... From c5903432e1488a8ab9b03f4bbdb2adacbc411d60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20Royer?= Date: Thu, 22 Aug 2024 12:40:57 +0200 Subject: [PATCH 6/7] Remove modulo from Vectordict.__pow__ This brings the signature in line with how Python defines the operator. The modulo parameter was not used. --- river/utils/vectordict.pyi | 2 +- river/utils/vectordict.pyx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/river/utils/vectordict.pyi b/river/utils/vectordict.pyi index 395681a239..faa8086966 100644 --- a/river/utils/vectordict.pyi +++ b/river/utils/vectordict.pyi @@ -43,7 +43,7 @@ class VectorDict: def __imul__(self, other): ... def __truediv__(left, right): ... def __itruediv__(self, other): ... - def __pow__(left, right, modulo): ... + def __pow__(left, right): ... def __ipow__(self, other): ... def __matmul__(left, right): ... def __neg__(self): ... 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) From 845348e885f1f495958c69c4b71e350f092e1b08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20Royer?= Date: Thu, 22 Aug 2024 13:51:18 +0200 Subject: [PATCH 7/7] Check the stubs files in pre-commit --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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