Skip to content

Commit 6a36be9

Browse files
RHOAIENG-24600 : Ensure Python 3.12 support for Python TrustyAI (#221)
* python 3.12 support and testing model pulled from https://github.com/trustyai-explainability/model-collection/tree/main/credit-bias * updated minimum python version and workflow test matrix * Update .github/workflows/workflow.yml * test: Disable pylint false positive * fix: formatting errors * fix: LIME formatting * fix: Upgrade pylint for 3.12.0 compatibility * fix: pylint in tMarco --------- Co-authored-by: Rui Vieira <[email protected]> Co-authored-by: Rui Vieira <[email protected]>
1 parent d16ff9e commit 6a36be9

34 files changed

+58171
-130
lines changed

.github/workflows/workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
python-version: [ 3.8, 3.9, 3.11 ]
10+
python-version: [ '3.10', '3.11', '3.12' ]
1111
java-version: [ 17 ]
1212
maven-version: [ '3.8.6' ]
1313
steps:

pyproject.toml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "Python bindings to the TrustyAI explainability library."
55
authors = [{ name = "Rui Vieira", email = "[email protected]" }]
66
license = { text = "Apache License Version 2.0" }
77
readme = "README.md"
8-
requires-python = ">=3.8"
8+
requires-python = ">=3.10"
99

1010
keywords = ["trustyai", "xai", "explainability", "ml"]
1111

@@ -15,19 +15,20 @@ classifiers = [
1515
"Intended Audience :: Developers",
1616
"Intended Audience :: Science/Research",
1717
"Programming Language :: Java",
18-
"Programming Language :: Python :: 3.8",
19-
"Programming Language :: Python :: 3.9",
18+
"Programming Language :: Python :: 3.10",
19+
"Programming Language :: Python :: 3.11",
20+
"Programming Language :: Python :: 3.12",
2021
"Topic :: Scientific/Engineering :: Artificial Intelligence",
2122
"Topic :: Software Development :: Libraries :: Java Libraries",
2223
]
2324

2425
dependencies = [
2526
"Jpype1==1.5.0",
26-
"pyarrow==17.0.0",
27-
"matplotlib~=3.6.3",
27+
"pyarrow==20.0.0",
28+
"matplotlib~=3.10.3",
2829
"pandas~=1.5.3",
29-
"numpy~=1.24.1",
30-
"jupyter-bokeh~=3.0.5",
30+
"numpy==1.26.4",
31+
"jupyter-bokeh~=3.0.7",
3132
]
3233

3334
[project.optional-dependencies]
@@ -38,15 +39,15 @@ dev = [
3839
"joblib~=1.2.0",
3940
"jupyterlab~=3.5.3",
4041
"numpydoc==1.5.0",
41-
"pylint==2.15.6",
42+
"pylint==3.2.0",
4243
"pytest~=7.2.1",
4344
"pytest-benchmark==4.0.0",
4445
"pytest-forked~=1.6.0",
45-
"scikit-learn~=1.2.1",
46+
"scikit-learn~=1.7.0",
4647
"setuptools",
4748
"twine==3.4.2",
4849
"wheel~=0.38.4",
49-
"xgboost==1.4.2",
50+
"xgboost~=3.0.2",
5051
]
5152
extras = ["aix360[default,tsice,tslime,tssaliency]==0.3.0"]
5253

src/trustyai/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
def init():
2222
"""Deprecated manual initializer for the JVM. This function has been replaced by
2323
automatic initialization when importing the components of the module that require
24-
JVM access, or by manual user initialization via :func:`trustyai`initializer.init`."""
24+
JVM access, or by manual user initialization via :func:`trustyai`initializer.init`.
25+
"""
2526
warnings.warn(
2627
"trustyai.init() is now deprecated; the trustyai library will now "
2728
+ "automatically initialize. For manual initialization options, see "

src/trustyai/explainers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Explainers module"""
2+
23
# pylint: disable=duplicate-code
34
from .counterfactuals import CounterfactualResult, CounterfactualExplainer
45
from .lime import LimeExplainer, LimeResults

src/trustyai/explainers/counterfactuals.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Explainers.countefactual module"""
2+
23
# pylint: disable = import-error, too-few-public-methods, wrong-import-order, line-too-long,
34
# pylint: disable = unused-argument
45
from typing import Optional, Union, List

src/trustyai/explainers/explanation_results.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Generic class for Explanation and Saliency results"""
2+
23
from abc import ABC, abstractmethod
34

45
import pandas as pd

src/trustyai/explainers/extras/tsice.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Wrapper module for TSICEExplainer from aix360.
33
Original at https://github.com/Trusted-AI/AIX360/
44
"""
5+
56
# pylint: disable=too-many-arguments,import-error
67
from typing import Callable, List, Optional, Union
78

@@ -46,7 +47,8 @@ def as_html(self) -> pd.io.formats.style.Styler:
4647

4748
def plot_forecast(self, variable): # pylint: disable=too-many-locals
4849
"""Plots the explanation.
49-
Based on https://github.com/Trusted-AI/AIX360/blob/master/examples/tsice/plots.py"""
50+
Based on https://github.com/Trusted-AI/AIX360/blob/master/examples/tsice/plots.py
51+
"""
5052
forecast_horizon = self.explanation["current_forecast"].shape[0]
5153
original_ts = pd.DataFrame(
5254
data={variable: self.explanation["data_x"][variable]}
@@ -161,7 +163,8 @@ def _add_timeseries(
161163

162164
def plot_impact(self, feature_per_row=2):
163165
"""Plot the impace.
164-
Based on https://github.com/Trusted-AI/AIX360/blob/master/examples/tsice/plots.py"""
166+
Based on https://github.com/Trusted-AI/AIX360/blob/master/examples/tsice/plots.py
167+
"""
165168

166169
n_row = int(np.ceil(len(self.explanation["feature_names"]) / feature_per_row))
167170
feat_values = np.array(self.explanation["feature_values"])

src/trustyai/explainers/extras/tslime.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def as_html(self) -> Styler:
3535

3636
def plot(self):
3737
"""Plot TSLime explanation for the time-series instance. Based on
38-
https://github.com/Trusted-AI/AIX360/blob/master/examples/tslime/tslime_univariate_demo.ipynb"""
38+
https://github.com/Trusted-AI/AIX360/blob/master/examples/tslime/tslime_univariate_demo.ipynb
39+
"""
3940
relevant_history = self.explanation["history_weights"].shape[0]
4041
input_data = self.explanation["input_data"]
4142
relevant_df = input_data[-relevant_history:]

src/trustyai/explainers/lime.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Explainers.lime module"""
2+
23
# pylint: disable = import-error, too-few-public-methods, wrong-import-order, line-too-long,
34
# pylint: disable = unused-argument, duplicate-code, consider-using-f-string, invalid-name
45
from typing import Dict, Union

src/trustyai/explainers/pdp.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Explainers.pdp module"""
2+
23
import math
34
import pandas as pd
45
from pandas.io.formats.style import Styler

0 commit comments

Comments
 (0)