diff --git a/eli5/_feature_weights.py b/eli5/_feature_weights.py index 47d71f9f..620f48fe 100644 --- a/eli5/_feature_weights.py +++ b/eli5/_feature_weights.py @@ -24,7 +24,7 @@ def _get_top_features(feature_names, coef, top): no more than ``num_neg`` negative features. """ if isinstance(top, (list, tuple)): - num_pos, num_neg = top + num_pos, num_neg = list(top) # "list" is just for mypy pos = _get_top_positive_features(feature_names, coef, num_pos) neg = _get_top_negative_features(feature_names, coef, num_neg) else: diff --git a/eli5/formatters/text.py b/eli5/formatters/text.py index 4c721558..d301b2df 100644 --- a/eli5/formatters/text.py +++ b/eli5/formatters/text.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import import six +from typing import List from . import fields from .features import FormattedFeatureName @@ -14,7 +15,7 @@ def format_as_text(expl, show=fields.ALL): - lines = [] + lines = [] # type: List[str] if expl.error: # always shown lines.extend(_error_lines(expl)) diff --git a/eli5/lime/samplers.py b/eli5/lime/samplers.py index d09fbca7..4d501d1d 100644 --- a/eli5/lime/samplers.py +++ b/eli5/lime/samplers.py @@ -2,7 +2,7 @@ from __future__ import absolute_import import abc import six -from typing import Tuple +from typing import List, Tuple import numpy as np @@ -145,8 +145,8 @@ class UnivariateKernelDensitySampler(_BaseKernelDensitySampler): of the features instead of generating totally new examples. """ def fit(self, X, y=None): - self.kdes_ = [] - self.grids_ = [] + self.kdes_ = [] # type: List[KernelDensity] + self.grids_ = [] # type: List[GridSearchCV] num_features = X.shape[-1] for i in range(num_features): grid, kde = self._fit_kde(self.kde, X[:, i].reshape(-1, 1)) diff --git a/eli5/sklearn/text.py b/eli5/sklearn/text.py index 1d193ba4..c928a6c6 100644 --- a/eli5/sklearn/text.py +++ b/eli5/sklearn/text.py @@ -1,4 +1,5 @@ import re +from typing import Set, Tuple from six.moves import xrange from sklearn.feature_extraction.text import VectorizerMixin @@ -56,7 +57,7 @@ def _get_features(feature): def _get_other(feature_weights, feature_weights_dict, found_features): # search for items that were not accounted at all. other_items = [] - accounted_keys = set() + accounted_keys = set() # type: Set[Tuple[str, int]] for feature, (_, key) in feature_weights_dict.items(): if key not in found_features and key not in accounted_keys: group, idx = key diff --git a/eli5/sklearn/unhashing.py b/eli5/sklearn/unhashing.py index a77398d5..9d49d8b3 100644 --- a/eli5/sklearn/unhashing.py +++ b/eli5/sklearn/unhashing.py @@ -6,7 +6,7 @@ from collections import defaultdict, Counter from itertools import chain -from typing import List, Iterable, Any +from typing import List, Iterable, Any, Dict import numpy as np from sklearn.base import BaseEstimator, TransformerMixin @@ -183,7 +183,7 @@ def _get_collisions(indices): Return a dict ``{column_id: [possible term ids]}`` with collision information. """ - collisions = defaultdict(list) + collisions = defaultdict(list) # type: Dict[int, List[int]] for term_id, hash_id in enumerate(indices): collisions[hash_id].append(term_id) return dict(collisions) diff --git a/eli5/sklearn/utils.py b/eli5/sklearn/utils.py index 377bff15..62dc6a10 100644 --- a/eli5/sklearn/utils.py +++ b/eli5/sklearn/utils.py @@ -96,7 +96,7 @@ def get_feature_names(clf, vec=None, bias_name='', feature_names=None): if feature_names.n_features != num_features: raise ValueError("feature_names has a wrong n_features: " "expected=%d, got=%d" % (num_features, - len(feature_names))) + feature_names.n_features)) # Make a shallow copy setting proper bias_name return FeatureNames( feature_names.feature_names, diff --git a/tox.ini b/tox.ini index ba30054e..df7c7d61 100644 --- a/tox.ini +++ b/tox.ini @@ -33,4 +33,4 @@ deps= {[testenv]deps} mypy-lang commands= - mypy --silent-imports eli5 + mypy --silent-imports --check-untyped-defs eli5