Skip to content
Merged
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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
python-version:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: ['3.9',
Expand All @@ -27,14 +27,14 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install setuptools==68.2.2 tox==3.24.5 tox-gh-actions==2.9.1
python -m pip install setuptools==68.2.2 tox==4.12.0 tox-gh-actions==3.2.0

- name: Optional - Install frouros (only used by linters)
if: matrix.python-version == 3.9
run: |
python -m venv .venv
source .venv/bin/activate
pip install "pytest>=7.1.2,<7.2"
pip install "pytest>=7.4.4,<7.5"
pip install -e .

- name: Run tox
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/code_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
jobs:
code-coverage:
if: github.event.pull_request.merged == true
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ permissions:

jobs:
publish:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version: 2

# Set the version of Python and other tools you might need
build:
os: ubuntu-20.04
os: ubuntu-22.04
tools:
python: "3.9"

Expand Down
4 changes: 2 additions & 2 deletions frouros/callbacks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ def set_detector(self, detector) -> None:
# )
# self._detector = value

def on_fit_start(self, X: np.ndarray) -> None: # noqa: N803
def on_fit_start(self, X: np.ndarray) -> None: # noqa: N803, B027
"""On fit start method.

:param X: reference data
:type X: numpy.ndarray
"""

def on_fit_end(self, X: np.ndarray) -> None: # noqa: N803
def on_fit_end(self, X: np.ndarray) -> None: # noqa: N803, B027
"""On fit end method.

:param X: reference data
Expand Down
13 changes: 10 additions & 3 deletions frouros/datasets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,17 @@ def _remove_temporal_file(self) -> None:

def _request_file(self, url: str) -> requests.models.Response:
logger.info("Trying to download data from %s to %s", url, self._file_path)
request_head = requests.head(url=url)
request_head = requests.head(
url=url,
timeout=10,
)
if not request_head.ok:
raise requests.exceptions.RequestException()
request_response = requests.get(url=url, stream=True)
request_response = requests.get(
url=url,
stream=True,
timeout=10,
)
request_response.raise_for_status()
return request_response

Expand Down Expand Up @@ -175,7 +182,7 @@ def __repr__(self) -> str:
)


class BaseDatasetGenerator(abc.ABC):
class BaseDatasetGenerator(abc.ABC): # noqa: B024
"""Abstract class representing a dataset generator."""

def __init__(self, seed: Optional[int] = None) -> None:
Expand Down
2 changes: 1 addition & 1 deletion frouros/detectors/concept_drift/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from frouros.utils.checks import check_callbacks


class BaseConceptDriftConfig(abc.ABC):
class BaseConceptDriftConfig(abc.ABC): # noqa: B024
"""Abstract class representing a concept drift configuration class."""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ def _update(self, value: Union[int, float], **kwargs) -> None:
self.num_instances
>= self.config.min_num_misclassified_instances # type: ignore
):

distance_threshold = (
self.mean_distance_error
+ self.config.level * self.std_distance_error # type: ignore
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""ChiSquareTest (Chi-square test) module."""

import collections
from typing import Optional, Tuple, Union
import typing
from typing import Optional, Set, Tuple, Union

import numpy as np # type: ignore
from scipy.stats import chi2_contingency # type: ignore
Expand Down Expand Up @@ -77,19 +78,20 @@ def _statistical_test(
return test

@staticmethod
@typing.no_type_check # FIXME: X_ref_counter and X_counter cause mypy errors # pylint: disable=fixme # noqa: E501
def _calculate_frequencies(
X_ref: np.ndarray, # noqa: N803
X: np.ndarray,
) -> Tuple[list[int], list[int]]:
X_ref_counter, X_counter = [ # noqa: N806
*map(collections.Counter, [X_ref, X]) # noqa: N806
]
possible_values = set([*X_ref_counter.keys()] + [*X_counter.keys()])
possible_values: Set[str] = set(
[*X_ref_counter.keys()] + [*X_counter.keys()]
) # noqa: N806
f_exp, f_obs = {}, {}
for value in possible_values:
f_exp[value] = X_ref_counter.get(value, 0)
f_obs[value] = X_counter.get(value, 0)
f_exp_values, f_obs_values = [
*map(list, [f_exp.values(), f_obs.values()]) # type: ignore
]
return f_exp_values, f_obs_values # type: ignore
f_exp[value] = X_ref_counter.get(value, 0) # noqa: N806
f_obs[value] = X_counter.get(value, 0) # noqa: N806
f_exp_values, f_obs_values = [*map(list, [f_exp.values(), f_obs.values()])]
return f_exp_values, f_obs_values
6 changes: 3 additions & 3 deletions frouros/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,9 @@ def train_prediction_normal(


@pytest.fixture(scope="module", name="dataset_simple")
def concept_drift_dataset_simple() -> Tuple[
Tuple[np.ndarray, np.ndarray], Tuple[np.ndarray, np.ndarray]
]:
def concept_drift_dataset_simple() -> (
Tuple[Tuple[np.ndarray, np.ndarray], Tuple[np.ndarray, np.ndarray]]
):
"""Dataset with multiple concepts to induce concept drift.

:return: dataset split in reference and test
Expand Down
30 changes: 15 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,26 @@ classifiers = [
]
requires-python = ">=3.9,<3.13"
dependencies = [
"matplotlib>=3.6.0,<3.9",
"numpy>=1.24.0,<1.27",
"matplotlib>=3.8.2,<3.9",
"numpy>=1.26.3,<1.27",
"requests>=2.31.0,<2.32",
"scipy>=1.10.0,<1.12",
"tqdm>=4.65,<5",
"scipy>=1.11.4,<1.12",
"tqdm>=4.66.1,<5.0",
]

[project.optional-dependencies]
docs = [
"sphinx>=5.3.0,<7.3",
"sphinx-book-theme>=1.0.0,<1.2",
"sphinxcontrib-bibtex>=2.5.0,<2.7",
"myst-parser>=0.18.0,<2.1",
"myst-nb>=0.17.0,<1.1",
"sphinx>=7.2.6,<7.3",
"sphinx-book-theme>=1.1.0,<1.2",
"sphinxcontrib-bibtex>=2.6.2,<2.7",
"myst-parser>=2.0.0,<2.1",
"myst-nb>=1.0.0,<1.1",
]
notebooks = [
"scikit-learn>=1.2.0,<1.4",
"torch>=1.13.0,<2.2",
"torchvision>=0.14.0,<0.17",
"ipywidgets>=8.0.0,<8.2",
"scikit-learn>=1.3.2,<1.4",
"torch>=2.1.2,<2.2",
"torchvision>=0.16.2,<0.17",
"ipywidgets>=8.1.1,<8.2",
]

[project.urls]
Expand All @@ -67,8 +67,8 @@ download = "https://pypi.org/project/frouros/"
[build-system]
requires = [
"setuptools>=61.0,<69.0",
"wheel>=0.37.1,<0.43",
"wheel>=0.42.0,<0.43",
"toml>=0.10.2,<0.11",
"build>=0.7.0,<1.1",
"build>=1.0.3,<1.1",
]
build-backend = "setuptools.build_meta"
30 changes: 14 additions & 16 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
minversion = 3.24.5
minversion = 4.12.0
envlist =
py3{9, 10, 11, 12}
linters
Expand All @@ -21,10 +21,10 @@ python =
# Force to upgrade pip/wheel/setuptools to the latest version
download = True
deps =
pytest>=7.2.1,<7.3
pytest-cov>=4.0.0,<4.1
pytest-mock>=3.10.0<3.11
scikit-learn>=1.2.0<1.3
pytest>=7.4.4,<7.5
pytest-cov>=4.1.0,<4.2
pytest-mock>=3.12.0,<3.13
scikit-learn>=1.3.2,<1.4
commands = pytest --cov={[base]package} \
--cov-report term \
--cov-report=xml
Expand All @@ -33,7 +33,7 @@ commands = pytest --cov={[base]package} \
basepython = {[base]python}
skip_install = {[base]skip_install}
deps =
black>=22.3,<22.4
black>=23.12.1,<24.0
commands = black --check --diff {[base]package}

[flake8]
Expand All @@ -53,19 +53,17 @@ exclude =
.venv,
.env
max-complexity = 10
format = ${cyan}%(path)s${reset}:${yellow_bold}%(row)d${reset}:${green_bold}%(col)d${reset}: ${red_bold}%(code)s${reset} %(text)s

[testenv:flake8]
basepython = {[base]python}
skip_install = {[base]skip_install}
deps =
flake8>=4.0,<4.1
flake8-bugbear>=22.3,<22.4
flake8-docstrings>=1.6,<1.7
flake8-typing-imports>=1.12,<1.13
flake8-colors>=0.1,<0.2
pep8-naming>=0.12,<0.13
pydocstyle>=6.1,<6.2
flake8>=7.0.0,<8.0
flake8-bugbear>=23.12.2,<24.0
flake8-docstrings>=1.7.0,<1.8
flake8-typing-imports>=1.15.0,<1.16
pep8-naming>=0.13.3,<0.14
pydocstyle>=6.3.0,<6.4
commands = flake8

[testenv:mypy]
Expand All @@ -74,7 +72,7 @@ skip_install = {[base]skip_install}
deps =
# FIXME: 0.971 version generates new unhandled warnings
mypy>=0.941,<0.971
types-requests
types-requests>=2.31.0,<2.32
plugins = numpy.typing.mypy_plugin
commands = mypy {[base]package}

Expand All @@ -86,7 +84,7 @@ norecursedirs = docs
basepython = {[base]python}
skip_install = {[base]skip_install}
deps =
pylint>=2.12,<2.13
pylint>=3.0.3,<3.1.0
commands =
pylint {[base]package} --good-names=b,d,df,e,f,h,i,j,m,n,p,w,x,y,z,r,X,en,js,kl,XY_chunks_combinations,X_chunks,X_chunks_combinations,X_concat,X_counter,X_extra,X_fold_test,X_fold_train,X_hist,X_merge,X_new_context,X_new_ref,X_num_samples,X_queue,X_sorted,X_percents,X_permuted,X_permuted_num_samples,X_permuted_,X_permuted_concat,X_permuted_ref_,X_permuted_ref_num_samples,X_preprocessed,X_ref,X_ref_hist,X_ref_counter,X_ref_percents,X_ref_rvs,X_ref_rv_histogram,X_rvs,X_rv_histogram,X_ref,_X_ref,X_ref_num_samples,X_ref_univariate,X_ref_multivariate,X_sample,X_samples,X_test,X_test_univariate,X_test_multivariate,X_train,y,Y,Y_chunks,Y_chunks_copy,Y_chunks_combinations,Y_hist,Y_percents,Y_num_samples,_X_num_samples --disable=too-many-instance-attributes,consider-using-with,too-few-public-methods --ignore-comments=yes --ignore-docstrings=yes --ignore-imports=yes --max-args=7 --min-similarity-lines=13 --extension-pkg-whitelist=scipy.special

Expand Down