Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔨 Remove usage of internal sklearn.utils api, replace with equivalent #214

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sklift/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .utils import check_is_binary
from .utils import check_is_binary, check_matplotlib_support

__all__ = ['check_is_binary']
__all__ = ['check_is_binary', 'check_matplotlib_support']
17 changes: 17 additions & 0 deletions sklift/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,20 @@ def check_is_binary(array):
raise ValueError(f"Input array is not binary. "
f"Array should contain only int or float binary values 0 (or 0.) and 1 (or 1.). "
f"Got values {np.unique(array)}.")


def check_matplotlib_support(caller_name):
"""Raise ImportError with detailed error message if mpl is not installed.
Plot utilities like any of the Display's plotting functions should lazily import
matplotlib and call this helper before any computation.

Args:
caller_name (str): The name of the caller that requires matplotlib.
"""
try:
import matplotlib # noqa
except ImportError as e:
raise ImportError(
"{} requires matplotlib. You can install matplotlib with "
"`pip install matplotlib`".format(caller_name)
) from e
3 changes: 1 addition & 2 deletions sklift/viz/base.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import matplotlib.pyplot as plt
import numpy as np
from sklearn.utils.validation import check_consistent_length
from sklearn.utils import check_matplotlib_support

from ..utils import check_is_binary
from ..utils import check_is_binary, check_matplotlib_support
from ..metrics import (
uplift_curve, perfect_uplift_curve, uplift_auc_score,
qini_curve, perfect_qini_curve, qini_auc_score,
Expand Down
Loading