Skip to content

Commit

Permalink
Merge branch 'MAIF:master' into feature/scikit_learn_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MLecardonnel authored Mar 28, 2024
2 parents 424793d + 9be4d36 commit 4902b1e
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
max-parallel: 1
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Shapash can use category-encoders object, sklearn ColumnTransformer or simply fe

## 🛠 Installation

Shapash is intended to work with Python versions 3.8 to 3.11. Installation can be done with pip:
Shapash is intended to work with Python versions 3.9 to 3.12. Installation can be done with pip:

```bash
pip install shapash
Expand Down
2 changes: 1 addition & 1 deletion docs/installation-instructions/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Installation instructions
Installing
----------

**Shapash** is intended to work with Python versions 3.8 to 3.11. Installation can be done with pip:
**Shapash** is intended to work with Python versions 3.9 to 3.12. Installation can be done with pip:

.. code:: bash
Expand Down
2 changes: 1 addition & 1 deletion requirements.dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dash-table==5.0.0
lightgbm==2.3.1
pandas>1.0.2
plotly==5.6.0
shap>=0.38.1
shap>=0.38.1,<0.45.0
Sphinx==4.5.0
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"matplotlib>=3.2.0",
"numpy>1.18.0",
"pandas>1.0.2",
"shap>=0.38.1",
"shap>=0.38.1,<0.45.0",
"Flask<2.3.0",
"dash>=2.3.1",
"dash-bootstrap-components>=1.1.0",
Expand Down Expand Up @@ -66,7 +66,7 @@
setup(
name="shapash",
version=version_d["__version__"],
python_requires=">3.7, <3.12",
python_requires=">3.8, <3.13",
url="https://github.com/MAIF/shapash",
author="Yann Golhen, Sebastien Bidault, Yann Lagre, Maxime Gendre",
author_email="yann.golhen@maif.fr",
Expand All @@ -75,10 +75,10 @@
long_description_content_type="text/markdown",
classifiers=[
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
],
Expand Down
2 changes: 1 addition & 1 deletion shapash/__version__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
VERSION = (2, 4, 2)
VERSION = (2, 4, 3)

__version__ = ".".join(map(str, VERSION))
16 changes: 3 additions & 13 deletions shapash/utils/category_encoder_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Category_encoder
"""

import category_encoders as ce
import numpy as np
import pandas as pd

Expand Down Expand Up @@ -54,12 +53,8 @@ def inv_transform_ce(x_in, encoding):
rst = inv_transform_ordinal(x, encoding.ordinal_encoder.mapping)

elif str(type(encoding)) == category_encoder_binary:
if ce.__version__ <= "2.2.2":
x = reverse_basen(x_in, encoding.base_n_encoder)
rst = inv_transform_ordinal(x, encoding.base_n_encoder.ordinal_encoder.mapping)
else:
x = reverse_basen(x_in, encoding)
rst = inv_transform_ordinal(x, encoding.ordinal_encoder.mapping)
x = reverse_basen(x_in, encoding)
rst = inv_transform_ordinal(x, encoding.ordinal_encoder.mapping)

elif str(type(encoding)) == category_encoder_targetencoder:
rst = inv_transform_target(x_in, encoding)
Expand Down Expand Up @@ -206,8 +201,6 @@ def calc_inv_contrib_ce(x_contrib, encoding, agg_columns):
The aggregate contributions depending on which processing is apply.
"""
if str(type(encoding)) in dummies_category_encoder:
if str(type(encoding)) in category_encoder_binary and ce.__version__ <= "2.2.2":
encoding = encoding.base_n_encoder
drop_col = []
for switch in encoding.mapping:
col_in = switch.get("col")
Expand Down Expand Up @@ -312,10 +305,7 @@ def get_col_mapping_ce(encoder):
]:
encoder_mapping = encoder.mapping
elif str(type(encoder)) == category_encoder_binary:
if ce.__version__ <= "2.2.2":
encoder_mapping = encoder.base_n_encoder.mapping
else:
encoder_mapping = encoder.mapping
encoder_mapping = encoder.mapping
else:
raise NotImplementedError(f"{encoder} not supported.")

Expand Down
7 changes: 4 additions & 3 deletions tests/unit_tests/explainer/test_smart_explainer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Unit test for smart explainer
"""

import os
import sys
import types
Expand Down Expand Up @@ -633,14 +634,14 @@ def test_load_1(self):
temp, xpl = init_sme_to_pickle_test()

current = Path(path.abspath(__file__)).parent.parent.parent
if str(sys.version)[0:3] == "3.8":
pkl_file = path.join(current, "data/xpl_to_load_38.pkl")
elif str(sys.version)[0:3] == "3.9":
if str(sys.version)[0:3] == "3.9":
pkl_file = path.join(current, "data/xpl_to_load_39.pkl")
elif str(sys.version)[0:4] == "3.10":
pkl_file = path.join(current, "data/xpl_to_load_310.pkl")
elif str(sys.version)[0:4] == "3.11":
pkl_file = path.join(current, "data/xpl_to_load_311.pkl")
elif str(sys.version)[0:4] == "3.12":
pkl_file = path.join(current, "data/xpl_to_load_312.pkl")
else:
raise NotImplementedError

Expand Down
17 changes: 5 additions & 12 deletions tests/unit_tests/utils/test_category_encoders_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,18 +739,11 @@ def test_get_col_mapping_ce_4(self):
enc.fit(test, y)

mapping = get_col_mapping_ce(enc)
if ce.__version__ <= "2.2.2":
expected_mapping = {
"city": ["city_0", "city_1", "city_2"],
"state": ["state_0", "state_1"],
"other": ["other_0", "other_1"],
}
else:
expected_mapping = {
"city": ["city_0", "city_1"],
"state": ["state_0", "state_1"],
"other": ["other_0", "other_1"],
}
expected_mapping = {
"city": ["city_0", "city_1"],
"state": ["state_0", "state_1"],
"other": ["other_0", "other_1"],
}

self.assertDictEqual(mapping, expected_mapping)

Expand Down
5 changes: 1 addition & 4 deletions tests/unit_tests/utils/test_columntransformer_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1178,10 +1178,7 @@ def test_get_col_mapping_ct_6(self):

test_encoded = pd.DataFrame(enc.fit_transform(test, y))
mapping = get_col_mapping_ct(enc, test_encoded)
if ce.__version__ <= "2.2.2":
expected_mapping = {"basen_city": [0, 1, 2], "basen_state": [3, 4]}
else:
expected_mapping = {"basen_city": [0, 1], "basen_state": [2, 3]}
expected_mapping = {"basen_city": [0, 1], "basen_state": [2, 3]}

self.assertDictEqual(mapping, expected_mapping)

Expand Down
5 changes: 3 additions & 2 deletions tests/unit_tests/utils/test_load_smartpredictor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Unit test smart predictor
"""

import sys
import unittest
from os import path
Expand Down Expand Up @@ -29,12 +30,12 @@ def test_load_smartpredictor_1(self):
current = Path(path.abspath(__file__)).parent.parent.parent
if str(sys.version)[0:4] == "3.10":
pkl_file = path.join(current, "data/predictor_to_load_310.pkl")
elif str(sys.version)[0:3] == "3.8":
pkl_file = path.join(current, "data/predictor_to_load_38.pkl")
elif str(sys.version)[0:3] == "3.9":
pkl_file = path.join(current, "data/predictor_to_load_39.pkl")
elif str(sys.version)[0:4] == "3.11":
pkl_file = path.join(current, "data/predictor_to_load_311.pkl")
elif str(sys.version)[0:4] == "3.12":
pkl_file = path.join(current, "data/predictor_to_load_312.pkl")
else:
raise NotImplementedError

Expand Down
3 changes: 3 additions & 0 deletions tutorial/generate_report/shapash_report_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
that generates the same report.
"""
import os
import sys

import pandas as pd
from category_encoders import OrdinalEncoder
from sklearn.ensemble import RandomForestRegressor
from sklearn.model_selection import train_test_split

sys.path.insert(0, "..")

from shapash import SmartExplainer
from shapash.data.data_loader import data_loading

Expand Down

0 comments on commit 4902b1e

Please sign in to comment.