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
27 changes: 25 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:

uv-example:
python:
name: python
runs-on: ubuntu-latest
strategy:
Expand All @@ -31,8 +31,31 @@ jobs:
run: uv python install ${{ matrix.python-version }}

- name: Install the project
run: uv sync --all-extras --dev
run: make install-tests

- name: Run tests
run: |
uv run pytest tests

notebooks:
name: notebooks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
version: "0.7.4"
enable-cache: true
cache-dependency-glob: "uv.lock"

- name: Set up Python
run: uv python install 3.13

- name: Install the project
run: make install-test-notebooks

- name: Run notebooks
run: |
make test-notebooks
29 changes: 20 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,41 @@ SHELL = /bin/bash
.PHONY: help
help:
@echo "Commands:"
@echo "install : install dependencies into virtual environment."
@echo "install-dev : install all, including dev, dependencies into virtual environment for local development."
@echo "update : Install new requriements into the virtual environment."
@echo "test : Run pytests."
@echo "coverage : Run pytest with coverage report"
@echo "install : Install dependencies into virtual environment."
@echo "install-dev : Install all, including dev, dependencies into virtual environment for local development."
@echo "update : Install new requriements into the virtual environment."
@echo "test : Run pytests."
@echo "test-notebooks : Execute all notebooks in nbs/."
@echo "coverage : Run pytest with coverage report"


.PHONY: install
install:
.PHONY: install-tests
install-tests:
uv sync

.PHONY: install-test-notebooks
install-test-notebooks:
uv sync --group nb

.PHONY: install-dev
install-dev:
uv sync --all-extras --dev && \
uv sync --all-extras && \
uv run pre-commit install

.PHONY: update
update:
uv sync --reinstall
uv sync --reinstall --group dev

.PHONY: test
test:
uv run pytest -vx tests

.PHONY: test-notebooks
test-notebooks:
set -e; for notebook in nbs/core/*.ipynb; do \
uv run jupyter execute --timeout=60 "$$notebook"; \
done

.PHONY: coverage
coverage:
uv run pytest --cov=src --cov-report html tests
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

* `src/random_tree_models/` -> python implementation of tree algorithms
* `tests/` -> unit tests
* `nbs/` -> jupyter notebooks to play with the tree algorithms
* `nbs/`
* `nbs/core` -> core jupyter notebooks to play with the tree algorithms
* `nbs/dev` -> other jupyter notebooks for other activities
* `config/` -> requirements.txt

## setup
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@
") -> pd.DataFrame:\n",
" execution_stats = []\n",
"\n",
" for n_samples, n_features in itertools.product(\n",
" n_samples_arr, n_features_arr\n",
" ):\n",
" for n_samples, n_features in itertools.product(n_samples_arr, n_features_arr):\n",
" X, y = sk_datasets.make_classification(\n",
" n_samples=n_samples,\n",
" n_features=n_features,\n",
Expand All @@ -125,9 +123,7 @@
" )\n",
" # sns.scatterplot(x=X[:, 0], y=X[:, 1], hue=y, alpha=0.3);\n",
"\n",
" model = xgboost.XGBoostClassifier(\n",
" use_hist=use_hist, n_bins=n_bins, max_depth=4\n",
" )\n",
" model = xgboost.XGBoostClassifier(use_hist=use_hist, n_bins=n_bins, max_depth=4)\n",
"\n",
" t0 = time.time()\n",
" model.fit(X, y)\n",
Expand Down Expand Up @@ -240,9 +236,7 @@
")\n",
"ax.set(title=\"score\", ylabel=\"score [roc auc]\")\n",
"\n",
"plt.suptitle(\n",
" \"Time DecisionTreeClassifier.* took based on n_samples and n_features\"\n",
")\n",
"plt.suptitle(\"Time DecisionTreeClassifier.* took based on n_samples and n_features\")\n",
"plt.tight_layout()"
]
},
Expand Down Expand Up @@ -315,9 +309,7 @@
") -> pd.DataFrame:\n",
" execution_stats = []\n",
"\n",
" for n_samples, n_features in itertools.product(\n",
" n_samples_arr, n_features_arr\n",
" ):\n",
" for n_samples, n_features in itertools.product(n_samples_arr, n_features_arr):\n",
" X, y = sk_datasets.make_classification(\n",
" n_samples=n_samples,\n",
" n_features=n_features,\n",
Expand All @@ -328,9 +320,7 @@
" )\n",
" # sns.scatterplot(x=X[:, 0], y=X[:, 1], hue=y, alpha=0.3);\n",
"\n",
" model = xgboost.XGBoostRegressor(\n",
" use_hist=use_hist, n_bins=n_bins, max_depth=4\n",
" )\n",
" model = xgboost.XGBoostRegressor(use_hist=use_hist, n_bins=n_bins, max_depth=4)\n",
"\n",
" t0 = time.time()\n",
" model.fit(X, y)\n",
Expand Down Expand Up @@ -444,9 +434,7 @@
")\n",
"ax.set(title=\"score\", ylabel=\"score [mse]\")\n",
"\n",
"plt.suptitle(\n",
" \"Time DecisionTreeRegressor.* took based on n_samples and n_features\"\n",
")\n",
"plt.suptitle(\"Time DecisionTreeRegressor.* took based on n_samples and n_features\")\n",
"plt.tight_layout()"
]
},
Expand Down Expand Up @@ -501,11 +489,6 @@
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
Expand Down
14 changes: 10 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ dependencies = [
"rich>=13.3.5",
"scikit-learn>=1.2.2",
"seaborn>=0.12.2",

]

[project.scripts]
random-tree-models = "random_tree_models:main"

[tool.uv]
default-groups = ["test"]

[tool.maturin]
module-name = "random_tree_models._core"
python-packages = ["random_tree_models"]
Expand All @@ -29,15 +31,19 @@ requires = ["maturin>=1.0,<2.0"]
build-backend = "maturin"

[dependency-groups]
dev = [
test = [
"pytest>=7.3.1",
"black>=23.3.0",
]
nb = [
"ipywidgets>=8.0.6",
"isort>=5.12.0",
"jupyter-contrib-nbextensions>=0.7.0",
"jupyterlab>=4.0.0",
]
dev = [
"pre-commit>=3.3.2",
"snakeviz>=2.2.0",
"pip-audit>=2.9.0",
"pytest-cov>=6.2.1",
{include-group = "nb"},
{include-group = "test"},
]
91 changes: 14 additions & 77 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading