Repository: deepchecks/deepchecks

Issue:
If all PPS == 0, then don't print graph
https://colab.research.google.com/drive/1HsSZol8PRKkczqpH1r4OA6qoRoxXTolv?usp=sharing



Discussion:

Resolving patch:
diff --git a/deepchecks/checks/distribution/plot.py b/deepchecks/checks/distribution/plot.py
--- a/deepchecks/checks/distribution/plot.py
+++ b/deepchecks/checks/distribution/plot.py
@@ -12,10 +12,9 @@
 import numpy as np
 import pandas as pd
 from scipy.stats import gaussian_kde
-import matplotlib.pyplot as plt
 import plotly.graph_objs as go
 
-__all__ = ['plot_density', 'feature_distribution_traces', 'drift_score_bar_traces', 'get_density']
+__all__ = ['feature_distribution_traces', 'drift_score_bar_traces', 'get_density']
 
 from typing import List, Union, Dict
 
@@ -23,28 +22,6 @@
 from deepchecks.utils.plot import colors
 
 
-def plot_density(data, xs, color='b', alpha: float = 0.7, **kwargs) -> np.ndarray:
-    """Plot a KDE density plot of the data. Adding labels and other plotting attributes is left to ths user.
-
-    Args:
-        data (): The data used to compute the pdf function.
-        xs (iterable): List of x values to plot the computed pdf for.
-        color (): Color of the filled graph.
-        alpha (float): Transparency of the filled graph.
-
-    Returns:
-        np.array: The computed pdf values at the points xs.
-    """
-    density = gaussian_kde(data)
-    density.covariance_factor = lambda: .25
-    # pylint: disable=protected-access
-    density._compute_covariance()
-    plt.fill_between(xs, density(xs), color=color, alpha=alpha, **kwargs)
-    plt.gca().set_ylim(bottom=0)
-
-    return density(xs)
-
-
 def get_density(data, xs) -> np.ndarray:
     """Get gaussian kde density to plot.
 
diff --git a/deepchecks/checks/methodology/identifier_leakage.py b/deepchecks/checks/methodology/identifier_leakage.py
--- a/deepchecks/checks/methodology/identifier_leakage.py
+++ b/deepchecks/checks/methodology/identifier_leakage.py
@@ -97,7 +97,10 @@ def _identifier_leakage(self, dataset: Union[pd.DataFrame, Dataset], ppscore_par
                 'For Identifier columns (Index/Date) PPS should be nearly 0, otherwise date and index have some '
                 'predictive effect on the label.']
 
-        return CheckResult(value=s_ppscore.to_dict(), display=[figure, *text])
+        # display only if not all scores are 0
+        display = [figure, *text] if s_ppscore.sum() else None
+
+        return CheckResult(value=s_ppscore.to_dict(), display=display)
 
     def add_condition_pps_not_greater_than(self, max_pps: float = 0):
         """Add condition - require columns not to have a greater pps than given max.
diff --git a/deepchecks/checks/methodology/single_feature_contribution.py b/deepchecks/checks/methodology/single_feature_contribution.py
--- a/deepchecks/checks/methodology/single_feature_contribution.py
+++ b/deepchecks/checks/methodology/single_feature_contribution.py
@@ -82,7 +82,10 @@ def plot(n_show_top=self.n_show_top):
                 ' actually due to data',
                 'leakage - meaning that the feature holds information that is based on the label to begin with.']
 
-        return CheckResult(value=s_ppscore.to_dict(), display=[plot, *text], header='Single Feature Contribution')
+        # display only if not all scores are 0
+        display = [plot, *text] if s_ppscore.sum() else None
+
+        return CheckResult(value=s_ppscore.to_dict(), display=display, header='Single Feature Contribution')
 
     def add_condition_feature_pps_not_greater_than(self: FC, threshold: float = 0.8) -> FC:
         """


Test patch:
diff --git a/deepchecks/checks/methodology/single_feature_contribution_train_test.py b/deepchecks/checks/methodology/single_feature_contribution_train_test.py
--- a/deepchecks/checks/methodology/single_feature_contribution_train_test.py
+++ b/deepchecks/checks/methodology/single_feature_contribution_train_test.py
@@ -139,7 +139,10 @@ def _single_feature_contribution_train_test(self, train_dataset: Dataset, test_d
         ret_value = {'train': s_pps_train.to_dict(), 'test': s_pps_test.to_dict(),
                      'train-test difference': s_difference.to_dict()}
 
-        return CheckResult(value=ret_value, display=[fig, *text], header='Single Feature Contribution Train-Test')
+        # display only if not all scores are 0
+        display = [fig, *text] if s_pps_train.sum() or s_pps_test.sum() else None
+
+        return CheckResult(value=ret_value, display=display, header='Single Feature Contribution Train-Test')
 
     def add_condition_feature_pps_difference_not_greater_than(self: FC, threshold: float = 0.2) -> FC:
         """Add new condition.