Skip to content

Commit

Permalink
Make tqdm a soft-dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Fred Branchaud committed Aug 14, 2020
1 parent 83cf67f commit 0da3ce0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
13 changes: 10 additions & 3 deletions fairlearn/reductions/_grid_search/grid_search.py
Expand Up @@ -9,7 +9,6 @@
from sklearn.dummy import DummyClassifier
from sklearn.utils.validation import check_is_fitted
from time import time
from tqdm import tqdm

from fairlearn._input_validation import _validate_and_reformat_input, _KW_SENSITIVE_FEATURES
from fairlearn.reductions._moments import Moment, ClassificationMoment
Expand All @@ -19,6 +18,7 @@
logger = logging.getLogger(__name__)

TRADEOFF_OPTIMIZATION = "tradeoff_optimization"
_TQDM_IMPORT_ERROR_MESSAGE = "To use `verbose=True` in GridSearch.fit, please install tqdm."


class GridSearch(BaseEstimator, MetaEstimatorMixin):
Expand Down Expand Up @@ -108,15 +108,22 @@ def fit(self, X, y, **kwargs):
:type sensitive_features: numpy.ndarray, pandas.DataFrame, pandas.Series, or list (for now)
:param verbose: An optional argument to enable/disable the progress bar.
Default: True
Default: False
:type verbose: bool
"""
self.predictors_ = []
self.lambda_vecs_ = pd.DataFrame(dtype=np.float64)
self.objectives_ = []
self.gammas_ = pd.DataFrame(dtype=np.float64)
self.oracle_execution_times_ = []
verbose = kwargs.pop('verbose', True)
verbose = kwargs.pop('verbose', False)

if verbose:
# We need tqdm to show the progress bar.
try:
from tqdm import tqdm
except ImportError:
raise RuntimeError(_TQDM_IMPORT_ERROR_MESSAGE)

if isinstance(self.constraints, ClassificationMoment):
logger.debug("Classification problem detected")
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Expand Up @@ -3,4 +3,3 @@ ipywidgets>=7.5.0
pandas>=0.25.1
scikit-learn>=0.22.1
scipy>=1.4.1
tqdm>=4.46.1

0 comments on commit 0da3ce0

Please sign in to comment.