Skip to content

Commit

Permalink
code suggestions from @CloseChoice
Browse files Browse the repository at this point in the history
Co-authored-by: Tobias Pitters <31857876+CloseChoice@users.noreply.github.com>
  • Loading branch information
Jordan Stomps and CloseChoice committed Dec 11, 2023
1 parent 5f6e58a commit 43d47f6
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion shap/maskers/_tabular.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ def fit(self, data):
Array to impute missing values for, should be masked
using missing_value.
"""
if len(data.shape) != 2:
raise NotImplementedError(f"Currently only 2 dimensional data can by processed with the LinearImpute class. You provided {len(data.shape)}. If this is crucial to you, feel free to open an issue: https://github.com/shap/shap/issues.")
self.data = pd.DataFrame(data)
self.data = self.data.replace(self.missing_value, np.NaN)
interpolated = self.data.interpolate(
Expand Down Expand Up @@ -376,7 +378,7 @@ def __init__(self, data, max_samples=100, method="mean"):
methods = ["linear", "mean", "median", "mode", "knn"]
if isinstance(method, str):
if method not in methods:
raise NotImplementedError("Given imputation method is not supported.")
raise NotImplementedError(f"Given imputation method is not supported. Please provide one of the following methods: {', '.join(methods)}")
elif method == "knn":
impute = KNNImputer(missing_values=0)
elif method == "linear":
Expand Down

0 comments on commit 43d47f6

Please sign in to comment.