Skip to content

Commit f932728

Browse files
Merge pull request #55 from predict-idlab/dev
- Added support for sklearn pipelines: #33 - Added support for fitting kwargs: #53 - Added support for Python 3.13: #45 - Solving issue: #46 - Solving issue: #54 - Removed support for tensorflow (and for this version DeepLearning, Pytorch is on the roadmap) - Migrated to uv from poetry
2 parents 148eaf5 + a70615a commit f932728

File tree

11 files changed

+2374
-2603
lines changed

11 files changed

+2374
-2603
lines changed

.github/workflows/test.yml

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ on:
99
paths:
1010
- "powershap/**"
1111
- "tests/**"
12-
- "poetry.lock"
12+
- "uv.lock"
1313
- ".github/workflows/test.yml"
1414
pull_request:
1515
branches: [ main ]
1616
paths:
1717
- "powershap/**"
1818
- "tests/**"
19-
- "poetry.lock"
19+
- "uv.lock"
2020
- ".github/workflows/test.yml"
2121

2222
jobs:
@@ -26,54 +26,48 @@ jobs:
2626
strategy:
2727
fail-fast: false
2828
matrix:
29-
os: ['ubuntu-latest'] # TODO - do we add other OSes?
30-
python-version: ["3.9", "3.10", "3.11", "3.12"]
29+
os: ['ubuntu-latest', 'windows-latest'] # TODO - do we add other OSes?
30+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
3131
defaults:
3232
run:
3333
shell: bash
3434

3535
steps:
36-
- uses: actions/checkout@v4
36+
- uses: actions/checkout@v5
37+
38+
- name: Install uv
39+
uses: astral-sh/setup-uv@v6
40+
with:
41+
enable-cache: true
42+
3743
- name: Set up Python ${{ matrix.python-version }}
38-
uses: actions/setup-python@v4
44+
uses: actions/setup-python@v5
3945
with:
4046
python-version: ${{ matrix.python-version }}
47+
48+
- name: Install llvm on Ubuntu
49+
if: runner.os == 'Linux'
50+
run: sudo apt-get install llvm # Because https://github.com/slundberg/shap/issues/1854
51+
52+
- name: Install MSVC build tools on Windows
53+
if: runner.os == 'Windows'
54+
uses: microsoft/setup-msbuild@v1
4155

42-
- name: Install Poetry
43-
uses: snok/install-poetry@v1
44-
with:
45-
version: 1.5.1
46-
- name: Cache poetry
47-
id: cached-poetry-dependencies
48-
uses: actions/cache@v3
49-
with:
50-
path: ~/.cache/pypoetry/virtualenvs
51-
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}-python-${{ matrix.python-version }}
52-
- run: poetry --version
5356

54-
- run: sudo apt-get install llvm # Because https://github.com/slundberg/shap/issues/1854
5557
- name: Install dependencies
56-
run: poetry install --all-extras
57-
# Do not use caching (anymore)
58-
# if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
58+
run: uv sync --locked --all-extras --dev
5959

60-
# - name: Lint with flake8
61-
# run: |
62-
# # stop the build if there are Python syntax errors or undefined names
63-
# flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
64-
# # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
65-
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
6660
- name: Test with pytest
67-
6861
run: |
69-
poetry run pytest --cov=powershap --junitxml=junit/test-results-${{ matrix.python-version }}.xml --cov-report=xml tests
62+
uv run pytest --cov=powershap --junitxml=junit/test-results-${{ matrix.python-version }}.xml --cov-report=xml tests
63+
7064
- name: Upload pytest test results
71-
uses: actions/upload-artifact@v3
65+
uses: actions/upload-artifact@v4
7266
with:
73-
name: pytest-results-${{ matrix.python-version }}
74-
path: junit/test-results-${{ matrix.python-version }}.xml
67+
name: pytest-results-${{ matrix.python-version }}-${{matrix.os}}
68+
path: junit/test-results-${{ matrix.python-version }}-${{matrix.os}}.xml
7569
# Use always() to always run this step to publish test results when there are test failures
7670
if: ${{ always() }}
7771

7872
- name: Upload coverage to Codecov
79-
uses: codecov/codecov-action@v3
73+
uses: codecov/codecov-action@v5

poetry.lock

Lines changed: 0 additions & 2438 deletions
This file was deleted.

powershap/powershap.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
from sklearn.base import BaseEstimator
99
from sklearn.feature_selection import SelectorMixin
1010
from sklearn.model_selection import BaseCrossValidator
11-
from sklearn.utils.validation import check_is_fitted
11+
from sklearn.utils.validation import check_is_fitted,validate_data
12+
13+
1214

1315
from .shap_wrappers import ShapExplainerFactory
1416
from .utils import powerSHAP_statistical_analysis
@@ -365,19 +367,21 @@ def fit(self, X, y, stratify=None, groups=None, **kwargs):
365367
# Perform the necessary sklearn checks -> X and y are both ndarray.
366368
# Logs the feature names as well (in self.feature_names_in_ in sklearn 1.x).
367369
#
368-
# These two operations (_validate_data and pd.DataFrame) will also copy
370+
# These two operations (validate_data and pd.DataFrame) will also copy
369371
# the data into a new place in memory, avoiding data mutation. How this
370372
# happens may not be obvious at first glance:
371373
#
372-
# 1. _validate_data ensures that the data is a numpy array, copying it
374+
# 1. validate_data ensures that the data is a numpy array, copying it
373375
# upon conversion if necessary.
374376
#
375377
# 2. pd.DataFrame then copies X, which is now an numpy array, into a
376378
# new pandas dataframe.
377379
#
378380
# If this is changed in some way which would allow explain() to mutate
379381
# the original data, it should cause the data mutation tests to fail.
380-
X, y = self._explainer._validate_data(self._validate_data, X, y, multi_output=True)
382+
383+
# X, y = validate_data(self, X, y, multi_output=True)
384+
X, y = self._explainer.validate_data(self, X, y, multi_output=True)
381385
X = pd.DataFrame(data=X, columns=list(range(X.shape[1])))
382386

383387
self._print("Starting powershap")
@@ -530,5 +534,8 @@ def transform(self, X):
530534
)
531535
return super().transform(X)
532536

533-
def _more_tags(self):
537+
# Since sklearn 1.6, the tag system changed so this function is necessary to make it compatible
538+
# https://scikit-learn.org/stable/auto_examples/release_highlights/plot_release_highlights_1_6_0.html#improvements-to-the-developer-api-for-third-party-libraries
539+
def __sklearn_tags__(self):
534540
return self._explainer._get_more_tags()
541+

0 commit comments

Comments
 (0)