Skip to content
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

Improve dependencies management and update versions #354

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
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
14 changes: 6 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ default_language_version:
python: python3.10
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-docstring-first
Expand All @@ -14,7 +14,7 @@ repos:
args: ["--branch", "main"]
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.6
rev: v0.8.1
hooks:
- id: ruff
types_or: [
Expand All @@ -30,17 +30,15 @@ repos:
jupyter,
]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.1
rev: v1.13.0
hooks:
- id: mypy
args: [
--strict,
--ignore-missing-imports,
--disable-error-code=misc,
--disable-error-code=no-any-return,
--config-file,
pyproject.toml,
]
additional_dependencies: [
types-requests<2.33,
types-toml<0.11,
types-tqdm<4.67,
types-tqdm<4.68,
]
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Recommended steps for first time contributors:
cd frouros
git checkout main
git pull
pip install -e .
pip install -e '.[dev]'
```
4. (Optional but recommended) Install pre-commit hooks:
```bash
Expand All @@ -33,5 +33,5 @@ Recommended steps for first time contributors:

## Reporting a bug

1. Check that there is not an [issue](https://github.com/IFCA/frouros/issues) that currently highlights the bug or a [pull request](https://github.com/IFCA/frouros/pulls) that solves it.
2. Create an [issue](https://github.com/IFCA/frouros/issues/new) in GitHub.
1. Check that there is not an [issue](https://github.com/IFCA-Advanced-Computing/frouros/issues) that currently highlights the bug or a [pull request](https://github.com/IFCA-Advanced-Computing/frouros/pulls) that solves it.
2. Create an [issue](https://github.com/IFCA-Advanced-Computing/frouros/issues/new) in GitHub.
10 changes: 5 additions & 5 deletions frouros/datasets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ def __init__(
:type file_path: str
"""
self.url = url
self.file_path: Optional[Path] = (
Path(file_path)
if file_path
else Path(tempfile.NamedTemporaryFile(delete=False).name)
)
if file_path:
self.file_path = Path(file_path)
else:
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
self.file_path = Path(temp_file.name)

@property
def file_path(self) -> Optional[Path]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _statistical_test(
x=X_ref,
y=X,
alternative=kwargs.get("alternative", "two-sided"),
method=kwargs.get("method", None),
method=kwargs.get("method"),
)
test = StatisticalResult(
statistic=test.statistic,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@

import collections
import typing
from typing import Any, Optional, Set, Tuple, Union
from typing import (
Any,
Optional,
Union,
)

import numpy as np
from scipy.stats import chi2_contingency

from frouros.callbacks.batch.base import BaseCallbackBatch
from frouros.detectors.data_drift.base import CategoricalData, UnivariateData
from frouros.detectors.data_drift.base import (
CategoricalData,
UnivariateData,
)
from frouros.detectors.data_drift.batch.statistical_test.base import (
BaseStatisticalTest,
StatisticalResult,
Expand Down Expand Up @@ -82,11 +89,11 @@ def _statistical_test(
def _calculate_frequencies(
X_ref: np.ndarray, # noqa: N803
X: np.ndarray,
) -> Tuple[list[int], list[int]]:
) -> tuple[list[int], list[int]]:
X_ref_counter, X_counter = [ # noqa: N806
*map(collections.Counter, [X_ref, X]) # noqa: N806
]
possible_values: Set[str] = set([*X_ref_counter.keys()] + [*X_counter.keys()]) # noqa: N806
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) # noqa: N806
Expand Down
2 changes: 1 addition & 1 deletion frouros/utils/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def permutation( # pylint: disable=too-many-arguments,too-many-locals
with Pool(processes=num_jobs) as pool:
permuted_statistics = pool.starmap_async(
partial(statistic, **statistical_args),
iterable=tqdm(permuted_data) if verbose else permuted_data, # type: ignore
iterable=tqdm(permuted_data) if verbose else permuted_data,
).get()

return permuted_statistics, max_num_permutations
21 changes: 20 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,30 @@ docs = [
"myst-nb>=1.0.0,<1.2",
]
notebooks = [
"scikit-learn>=1.3.2,<1.6",
"scikit-learn>=1.5.1,<1.6",
"torch>=2.1.2,<2.6",
"torchvision>=0.16.2,<0.21",
"ipywidgets>=8.1.1,<8.2",
]
dev-tests = [
"pytest>=8.3.1,<8.4",
"pytest-cov>=6.0.0,<6.1",
"pytest-mock>=3.14.0,<3.15",
"scikit-learn>=1.5.1,<1.6",
]
dev-ruff = [
"ruff>=0.8.1,<0.9",
]
dev-mypy = [
"mypy>=1.13.0,<1.14",
"types-requests>=2.32.0,<2.33",
"types-toml>=0.10.0,<0.11",
"types-tqdm>=4.66,<4.68",
]
dev = [
"frouros[docs,notebooks,dev-tests,dev-ruff,dev-mypy]",
"tox>=4.23.2,<4.24",
]

[project.urls]
homepage = "https://frouros.readthedocs.io"
Expand Down
44 changes: 28 additions & 16 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
minversion = 4.16.0
minversion = 4.23.2
envlist =
py3{9, 10, 11, 12}
linters
Expand All @@ -9,6 +9,12 @@ python = python3
skip_install = true
package = frouros
venv = {toxinidir}/.venv
deps =
# Package used as a workaround to install the dependencies read from pyproject.toml dev section.
toml>=0.10.2,<0.11
pyproject_reader =
# Workaround to install the dependencies read from pyproject.toml dev section.
python -c "import toml, subprocess; deps = toml.load('pyproject.toml')['project']['optional-dependencies']['{env:DEPS_SECTION}']; subprocess.run(['pip', 'install'] + deps)"

[gh-actions]
python =
Expand All @@ -20,12 +26,13 @@ python =
[testenv]
# Force to upgrade pip/wheel/setuptools to the latest version
download = True
deps =
pytest>=8.3.1,<8.4
pytest-cov>=5.0.0,<5.1
pytest-mock>=3.14.0,<3.15
scikit-learn>=1.5.1,<1.6
commands = pytest --cov={[base]package} \
deps = {[base]deps}
setenv =
DEPS_SECTION = dev-tests
commands_pre =
{[base]pyproject_reader}
commands =
pytest --cov={[base]package} \
--cov-report term \
--cov-report=xml \
--cov-fail-under=90
Expand All @@ -37,19 +44,22 @@ norecursedirs = docs
[testenv:ruff]
basepython = {[base]python}
skip_install = {[base]skip_install}
deps =
ruff>=0.5.6,<0.6
deps = {[base]deps}
setenv =
DEPS_SECTION = dev-ruff
commands_pre =
{[base]pyproject_reader}
commands = ruff check --config pyproject.toml .
ruff format --config pyproject.toml .

[testenv:mypy]
basepython = {[base]python}
skip_install = {[base]skip_install}
deps =
mypy>=1.11.0,<1.12
types-requests>=2.32.0,<2.33
types-toml>=0.10.0,<0.11
types-tqdm>=4.66,<4.67
deps = {[base]deps}
setenv =
DEPS_SECTION = dev-mypy
commands_pre =
{[base]pyproject_reader}
commands = mypy --config-file pyproject.toml .

[testenv:linters]
Expand All @@ -58,8 +68,10 @@ skip_install = {[base]skip_install}
setenv =
PYTHONPATH = $PYTHONPATH:{toxinidir}:{[base]venv}/lib/{[base]python}/site-packages
deps =
{[testenv:ruff]deps}
{[testenv:mypy]deps}
{[base]deps}
commands_pre =
{[testenv:ruff]commands_pre}
{[testenv:mypy]commands_pre}
commands =
{[testenv:ruff]commands}
{[testenv:mypy]commands}
Loading