Skip to content

Commit fea00c5

Browse files
author
Giovanni Giacometti
authored
Merge pull request #10 from ml-cube/dev
feat: new algorithms + various improvements
2 parents 7bbbfdc + 79d922a commit fea00c5

45 files changed

Lines changed: 3609 additions & 1682 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/actions/validation/action.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ description: format, lint, test code
33
runs:
44
using: "composite"
55
steps:
6-
76
- name: 📦 Install uv
87
uses: astral-sh/setup-uv@v6
98

@@ -17,7 +16,7 @@ runs:
1716

1817
- name: 🦾 💅 🧪 Install and validate extras
1918
run: |
20-
extras=("sklearn" "huggingface")
19+
extras=("sklearn" "huggingface" "polars" "pandas")
2120
2221
for extra in "${extras[@]}"; do
2322
echo "🦾 Installing extra: $extra"

Justfile

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,63 @@ set quiet
77
default:
88
just --list --unsorted
99

10+
# --------------------------------------------------
11+
# Developer Setup
12+
1013
# Synchronize the environment by installing all the dependencies
1114
dev-sync:
1215
uv sync --cache-dir .uv_cache --all-extras
1316

17+
# Synchronize the environment by installing the specified extra dependency
18+
# Currently used within the CI to install extra dependencies and test them.
1419
dev-sync-extra extra:
1520
uv sync --cache-dir .uv_cache --extra {{extra}}
1621

1722
# Synchronize the environment by installing all the dependencies except the dev ones
1823
prod-sync:
19-
uv sync --cache-dir .uv_cache --all-extras --no-dev
24+
uv sync --cache-dir .uv_cache --all-extras --no-default-groups
25+
26+
# Synchronize the environment by installing the extra dependency
27+
# specified. Doesn't install the dev dependencies.
28+
prod-sync-extra extra:
29+
uv sync --cache-dir .uv_cache --extra {{extra}} --no-default-groups
2030

2131
# Install the pre-commit hooks
2232
install-hooks:
2333
uv run pre-commit install
2434

35+
# --------------------------------------------------
36+
# Validation
37+
2538
# Run ruff formatting
2639
format:
2740
uv run ruff format
2841

2942
# Run ruff linting and mypy type checking
3043
lint:
3144
uv run ruff check --fix
32-
uv run mypy --ignore-missing-imports --install-types --non-interactive --package ml3_drift
45+
uv run mypy --ignore-missing-imports --install-types --non-interactive --package ml3_drift --python-version 3.10
46+
47+
48+
# Default value for testWorkers is auto (meaning all workers available)
49+
# If you want to pass a custom value (such as 4): `just testWorkers=4 test`
50+
# We also run ruff on tests files (it's so fast that it's worth it)
51+
52+
# Little caveat: when running tests with only an extra installed, you'd like
53+
# to avoid having docs dependencies installed (since, for instance, a mkdocs plugin
54+
# requires Pandas, which is one of our extra dependencies). This happens by default
55+
# since docs dependencies are not installed as default dependencies by uv (see pyproject.toml).
56+
# They are only installed when building / serving the documentation. However, if you first
57+
# build the documentation, then run the tests, you will have the docs dependencies installed.
58+
# Should not be a practical problem (especially since in CI environments we don't install docs dependencies),
59+
# but it's worth noting.
3360

3461
# Run the tests with pytest
62+
testWorkers := "auto"
3563
test:
36-
uv run pytest --verbose --color=yes -n auto --exitfirst tests
64+
uv run ruff format tests
65+
uv run ruff check tests --fix
66+
uv run pytest --verbose --color=yes -n {{testWorkers}} --exitfirst tests
3767

3868
# Run linters, formatters and tests
3969
validate: format lint test
@@ -43,11 +73,12 @@ validate: format lint test
4373

4474
# Generate the documentation
4575
build-docs:
46-
uv run mkdocs build
76+
# Make sure mkdocs is installed
77+
uv run --group docs mkdocs build
4778

4879
# Serve the documentation locally
4980
serve-docs:
50-
uv run mkdocs serve
81+
uv run --group docs mkdocs serve
5182

5283
# --------------------------------------------------
5384
# Publishing

examples/huggingface/text_embedding_monitoring.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
from ml3_drift.huggingface.drift_detection_pipeline import (
44
HuggingFaceDriftDetectionPipeline,
55
)
6-
from ml3_drift.huggingface.univariate.ks import KSDriftDetector
6+
from ml3_drift.monitoring.algorithms.batch.bonferroni import (
7+
BonferroniCorrectionAlgorithm,
8+
)
9+
from ml3_drift.monitoring.algorithms.batch.ks import KSAlgorithm
710
from ml3_drift.callbacks.base import logger_callback
811

912

@@ -37,7 +40,8 @@
3740
# to monitor the drift in the embeddings.
3841

3942
hf_pipe = HuggingFaceDriftDetectionPipeline(
40-
drift_detector=KSDriftDetector(
43+
drift_detector=BonferroniCorrectionAlgorithm(
44+
algorithm=KSAlgorithm(p_value=0.05),
4145
callbacks=[
4246
partial(
4347
logger_callback,

pyproject.toml

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,28 @@ dynamic = ["version"]
77
license = { text = "Apache-2.0" }
88
readme = "README.md"
99

10-
dependencies = []
10+
dependencies = [
11+
"scipy>=1.15.3",
12+
]
1113

1214
# -------------------------------------------------
1315
# Extra dependencies. This package is designed to be
14-
# used within one extra at a time, hence we check each
15-
# extra separately. Remember to update the list of extras
16-
# in the validation action to ensure tests are run
16+
# used with different libraries, which means that our code
17+
# should work only when not all extras are installed.
18+
# Remember to update the list of extras
19+
# in the validation CICD to ensure tests are run
1720
# for your new extra
1821
[project.optional-dependencies]
1922

2023
sklearn = ["scikit-learn>=1.6.1"]
2124

22-
huggingface = ["scipy>=1.15.2", "transformers[torch]>=4.52.3"]
25+
huggingface = ["transformers[torch]>=4.52.3"]
26+
27+
polars = ["polars>=1.31.0"]
28+
29+
pandas = ["pandas>=2.2.3"]
30+
31+
river = ["river>=0.22.0"]
2332

2433

2534
# -------------------------------------------------
@@ -28,31 +37,45 @@ huggingface = ["scipy>=1.15.2", "transformers[torch]>=4.52.3"]
2837
dev = [
2938
"ipykernel>=6.29.5",
3039
"mypy>=1.15.0",
31-
"pillow>=11.2.1", # for image support in tests
3240
"pre-commit>=4.1.0",
3341
"pytest>=8.3.4",
3442
"pytest-xdist>=3.6.1",
3543
"ruff>=0.9.5",
36-
# for docs
44+
# for image support in tests
45+
"pillow>=11.2.1",
46+
]
47+
48+
docs = [
49+
"mkdocs-minify-plugin>=0.7.1",
50+
"mkdocs-glightbox>=0.3.4",
51+
"mkdocs-table-reader-plugin>=2.0.1",
52+
"mkdocs-macros-plugin",
3753
"mkdocs>=1.5.0",
3854
"mkdocs-material>=9.5.0",
3955
"mkdocs-material-extensions>=1.1",
4056
"pygments>=2.14",
4157
"pymdown-extensions>=9.9.1",
4258
"jinja2>=3.0",
4359
"markdown>=3.2",
44-
"mkdocs-minify-plugin>=0.7.1",
45-
"mkdocs-glightbox>=0.3.4",
46-
"mkdocs-table-reader-plugin>=2.0.1",
47-
"mkdocs-macros-plugin",
4860
"openpyxl",
4961
]
5062

5163
# -------------------------------------------------
5264

65+
# Default groups for uv
66+
[tool.uv]
67+
default-groups = ["dev"]
68+
69+
# -------------------------------------------------
70+
5371
[build-system]
5472
requires = ["hatchling"]
5573
build-backend = "hatchling.build"
5674

5775
[tool.hatch.version]
5876
path = "src/ml3_drift/__init__.py"
77+
78+
79+
# Set pytest folder
80+
[tool.pytest.ini_options]
81+
testpaths = ["tests"]

ruff.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ exclude = [
3333
line-length = 88
3434
indent-width = 4
3535

36-
# Assume Python 3.9
37-
target-version = "py39"
38-
3936
[lint]
4037
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
4138
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)