Skip to content

Commit b01678f

Browse files
Merge pull request #636 from guillaume-vignal/fix/Tuple_List
Refactor deprecated typing.List and typing.Tuple usage
2 parents 19167b3 + 408f6d1 commit b01678f

File tree

10 files changed

+27
-27
lines changed

10 files changed

+27
-27
lines changed

shapash/backend/base_backend.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from abc import ABC, abstractmethod
2-
from typing import Any, List, Optional, Union
2+
from typing import Any, Optional, Union
33

44
import numpy as np
55
import pandas as pd
@@ -68,8 +68,8 @@ def run_explainer(self, x: pd.DataFrame) -> dict:
6868
)
6969

7070
def get_local_contributions(
71-
self, x: pd.DataFrame, explain_data: Any, subset: Optional[List[int]] = None
72-
) -> Union[pd.DataFrame, List[pd.DataFrame]]:
71+
self, x: pd.DataFrame, explain_data: Any, subset: Optional[list[int]] = None
72+
) -> Union[pd.DataFrame, list[pd.DataFrame]]:
7373
"""Get local contributions using the explainer data computed in the `run_explainer`
7474
method.
7575
@@ -110,9 +110,9 @@ def get_global_features_importance(
110110
self,
111111
contributions: pd.DataFrame,
112112
explain_data: Optional[dict] = None,
113-
subset: Optional[List[int]] = None,
113+
subset: Optional[list[int]] = None,
114114
norm: int = 1,
115-
) -> Union[pd.Series, List[pd.Series]]:
115+
) -> Union[pd.Series, list[pd.Series]]:
116116
"""Get global contributions using the explainer data computed in the `run_explainer`
117117
method.
118118
@@ -141,8 +141,8 @@ def get_global_features_importance(
141141
def format_and_aggregate_local_contributions(
142142
self,
143143
x: pd.DataFrame,
144-
contributions: Union[pd.DataFrame, np.array, List[pd.DataFrame], List[np.array]],
145-
) -> Union[pd.DataFrame, List[pd.DataFrame]]:
144+
contributions: Union[pd.DataFrame, np.array, list[pd.DataFrame], list[np.array]],
145+
) -> Union[pd.DataFrame, list[pd.DataFrame]]:
146146
"""
147147
This function allows to format and aggregate contributions in the right format
148148
(pd.DataFrame or list of pd.DataFrame).
@@ -175,8 +175,8 @@ def format_and_aggregate_local_contributions(
175175
return contributions
176176

177177
def _apply_preprocessing(
178-
self, contributions: Union[pd.DataFrame, List[pd.DataFrame]]
179-
) -> Union[pd.DataFrame, List[pd.DataFrame]]:
178+
self, contributions: Union[pd.DataFrame, list[pd.DataFrame]]
179+
) -> Union[pd.DataFrame, list[pd.DataFrame]]:
180180
"""
181181
Reconstruct contributions for original features, taken into account a preprocessing.
182182

shapash/explainer/smart_explainer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ def check_features_name(self, features, use_groups=False):
692692
Features names can be part of columns_dict or features_dict.
693693
Parameters
694694
----------
695-
features : List
695+
features : list
696696
List of ints (columns ids) or of strings (business names)
697697
use_groups : bool
698698
Whether or not features parameter includes groups of features

shapash/explainer/smart_predictor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ def check_features_name(self, features):
748748
749749
Parameters
750750
----------
751-
features : List
751+
features : list
752752
List of ints (columns ids) or of strings (business names)
753753
754754
Returns

shapash/explainer/smart_state.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def hide_contributions(self, var_dict, features_list):
154154
var_dict: pd.DataFrame
155155
Dataframe with features indexes ordered
156156
by contribution.
157-
feature_list: List
157+
feature_list: list
158158
List of index, feature to hide.
159159
160160
Returns

shapash/report/project_report.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sys
55
from datetime import date
66
from numbers import Number
7-
from typing import Optional, Tuple, Union
7+
from typing import Optional, Union
88

99
import jinja2
1010
import numpy as np
@@ -137,7 +137,7 @@ def __init__(
137137
@staticmethod
138138
def _get_values_and_name(
139139
y: Optional[Union[pd.DataFrame, pd.Series, list]], default_name: str
140-
) -> Union[Tuple[list, str], Tuple[None, None]]:
140+
) -> Union[tuple[list, str], tuple[None, None]]:
141141
"""
142142
Extracts vales and column name from a Pandas Series, DataFrame, or assign a default
143143
name if y is a list of values.

shapash/utils/check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ def check_features_name(columns_dict, features_dict, features):
422422
423423
Parameters
424424
----------
425-
features : List
425+
features : list
426426
List of ints (columns ids) or of strings (business names)
427427
columns_dict: dict
428428
Dictionary mapping integer column number to technical feature names.

shapash/utils/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def extract_features_model(model, model_attribute):
1414
-------
1515
model: model object
1616
model used to check the different values of target estimate predict proba
17-
model_attribute: String or List
17+
model_attribute: String or list
1818
if model can give features, attributes to access features, if not 'length'
1919
"""
2020
if model_attribute[0] == "length":

shapash/utils/transform.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def preprocessing_tolist(preprocess):
138138
139139
Returns
140140
-------
141-
List
141+
list
142142
A list containing all preprocessing.
143143
"""
144144
list_encoding = preprocess if isinstance(preprocess, list) else [preprocess]

shapash/utils/translate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def translate(elements, mapping):
1616
1717
Returns
1818
-------
19-
List
19+
list
2020
The list of business names (strings) obtained.
2121
"""
2222
return [mapping[element] for element in elements]

shapash/webapp/utils/callbacks.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import datetime
2-
from typing import TYPE_CHECKING, Optional, Tuple, Union
2+
from typing import TYPE_CHECKING, Optional, Union
33

44
if TYPE_CHECKING:
55
from shapash.explainer.smart_explainer import SmartExplainer
@@ -335,7 +335,7 @@ def get_feature_contributions_sign_to_show(positive: list, negative: list) -> Op
335335
return sign
336336

337337

338-
def update_features_to_display(features: int, nb_columns: int, value: int) -> Tuple[int, int, dict]:
338+
def update_features_to_display(features: int, nb_columns: int, value: int) -> tuple[int, int, dict]:
339339
"""Update features to display slider.
340340
341341
Parameters
@@ -349,7 +349,7 @@ def update_features_to_display(features: int, nb_columns: int, value: int) -> Tu
349349
350350
Returns
351351
-------
352-
Tuple[int, int, dict]
352+
tuple[int, int, dict]
353353
Number of columns to plot, Number max of columns to plot, Marks in the slider
354354
"""
355355
max_value = min(features, nb_columns)
@@ -696,7 +696,7 @@ def create_filter_modalities_selection(value: str, id: dict, round_dataframe: pd
696696
return new_element
697697

698698

699-
def handle_page_navigation(triggered_input: str, page: Union[int, str], selected_feature: str) -> Tuple[int, str]:
699+
def handle_page_navigation(triggered_input: str, page: Union[int, str], selected_feature: str) -> tuple[int, str]:
700700
"""
701701
Handle the navigation between different pages based on user input.
702702
@@ -706,7 +706,7 @@ def handle_page_navigation(triggered_input: str, page: Union[int, str], selected
706706
selected_feature (str): The currently selected feature.
707707
708708
Returns:
709-
Tuple[int, str]: Updated page number and selected feature.
709+
tuple[int, str]: Updated page number and selected feature.
710710
"""
711711
page = int(page)
712712
if triggered_input == "page_left.n_clicks":
@@ -765,7 +765,7 @@ def handle_group_display_logic(
765765
selected_click_data_store,
766766
features_groups: dict,
767767
features_dict: dict,
768-
) -> Tuple[str, str, dict]:
768+
) -> tuple[str, str, dict]:
769769
"""
770770
Handle the display logic for feature groups.
771771
@@ -779,7 +779,7 @@ def handle_group_display_logic(
779779
features_dict (dict): Dictionary of features.
780780
781781
Returns:
782-
Tuple[str, str, dict]: Updated selected feature, group name, and click data.
782+
tuple[str, str, dict]: Updated selected feature, group name, and click data.
783783
"""
784784
group_name = None
785785
selected_feature_group = None
@@ -818,7 +818,7 @@ def handle_group_display_logic(
818818

819819
def determine_total_pages_and_display(
820820
explainer: "SmartExplainer", features: int, bool_group: bool, group_name: str, page: int
821-
) -> Tuple[int, str, int]:
821+
) -> tuple[int, str, int]:
822822
"""
823823
Determine the total number of pages and the display properties.
824824
@@ -830,7 +830,7 @@ def determine_total_pages_and_display(
830830
page (int): Current page number.
831831
832832
Returns:
833-
Tuple[int, str, int]: Total pages, display properties, and updated page number.
833+
tuple[int, str, int]: Total pages, display properties, and updated page number.
834834
"""
835835
display_groups = explainer.features_groups is not None and bool_group
836836
if explainer._case == "classification":

0 commit comments

Comments
 (0)