Skip to content

Commit

Permalink
Merge pull request #281 from krkd/master
Browse files Browse the repository at this point in the history
Prefer singledispatch from standart library
  • Loading branch information
lopuhin authored Nov 5, 2018
2 parents 63e9918 + e0725aa commit 7218e0d
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ matrix:
env: TOXENV=mypy
- python: 3.6
env: TOXENV=docs
- python: 3.7
dist: xenial
sudo: true
env: TOXENV=py37-nodeps

addons:
apt:
Expand Down
5 changes: 5 additions & 0 deletions eli5/base_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

import attr # type: ignore

try:
from functools import singledispatch # type: ignore
except ImportError:
from singledispatch import singledispatch # type: ignore


def attrs(class_):
""" Like attr.s with slots=True,
Expand Down
3 changes: 1 addition & 2 deletions eli5/explain.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
Dispatch module. Explanation functions for conctere estimator classes
are defined in submodules.
"""
from singledispatch import singledispatch

from eli5.base import Explanation
from eli5.base_utils import singledispatch


@singledispatch
Expand Down
2 changes: 1 addition & 1 deletion eli5/formatters/as_dataframe.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from itertools import chain
from singledispatch import singledispatch
from typing import Any, Dict, List, Optional
import warnings

Expand All @@ -10,6 +9,7 @@
Explanation, FeatureImportances, TargetExplanation,
TransitionFeatureWeights,
)
from eli5.base_utils import singledispatch


def explain_weights_df(estimator, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion eli5/lightning.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from singledispatch import singledispatch

from lightning.impl.base import BaseEstimator # type: ignore
from lightning import classification, regression # type: ignore
from sklearn.multiclass import OneVsRestClassifier # type: ignore

from eli5.base import Explanation
from eli5.base_utils import singledispatch
from eli5.sklearn import (
explain_linear_classifier_weights,
explain_linear_regressor_weights,
Expand Down
2 changes: 1 addition & 1 deletion eli5/sklearn/explain_prediction.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from singledispatch import singledispatch
from functools import partial

import numpy as np # type: ignore
Expand Down Expand Up @@ -51,6 +50,7 @@
)

from eli5.base import Explanation, TargetExplanation
from eli5.base_utils import singledispatch
from eli5.utils import (
get_target_display_names,
get_binary_target_scale_label_id
Expand Down
2 changes: 1 addition & 1 deletion eli5/sklearn/explain_weights.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from singledispatch import singledispatch

import numpy as np # type: ignore

Expand Down Expand Up @@ -57,6 +56,7 @@

from eli5.base import (
Explanation, TargetExplanation, FeatureImportances)
from eli5.base_utils import singledispatch
from eli5._feature_weights import get_top_features
from eli5.utils import argsort_k_largest_positive, get_target_display_names
from eli5.sklearn.unhashing import handle_hashing_vec, is_invhashing
Expand Down
2 changes: 1 addition & 1 deletion eli5/transform.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Handling transformation pipelines in explanations"""

from singledispatch import singledispatch
from eli5.base_utils import singledispatch


@singledispatch
Expand Down
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@ def get_long_description():
'jinja2',
'numpy >= 1.9.0',
'scipy',
'singledispatch >= 3.4.0.3',
'six',
'scikit-learn >= 0.18',
'typing',
'graphviz',
'tabulate>=0.7.7',
],
extras_require={
":python_version<'3.5.6'": [
'singledispatch >= 3.4.0.3',
],
},
classifiers=[
'Development Status :: 4 - Beta',
'License :: OSI Approved :: MIT License',
Expand All @@ -54,5 +58,6 @@ def get_long_description():
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
],
)
7 changes: 6 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
; https://github.com/Microsoft/LightGBM/tree/master/python-package#lightgbm-python-package.

[tox]
envlist = py27,py34,py35,py35-nodeps,mypy,py35-extra,py27-extra,py36,py36-extra,py36-legacy
envlist = py27,py34,py35,py35-nodeps,mypy,py35-extra,py27-extra,py36,py36-extra,py36-legacy,py37-nodeps

[base]
deps=
Expand Down Expand Up @@ -94,3 +94,8 @@ deps=
changedir=docs/source
commands=
sphinx-build -W -b html . {envtmpdir}/html


[testenv:py37-nodeps]
deps={[base]deps}
commands={[testenv:py35-nodeps]commands}

0 comments on commit 7218e0d

Please sign in to comment.