Skip to content

Added support for Jinja2 3.1.2 and scikit-learn 1.0.2 #418

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

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 8 additions & 5 deletions eli5/formatters/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
from .trees import tree2text
from .text_helpers import prepare_weighted_spans, PreparedWeightedSpans


template_env = Environment(
loader=PackageLoader('eli5', 'templates'),
extensions=['jinja2.ext.with_'])
try:
template_env = Environment(
loader=PackageLoader('eli5', 'templates'),
extensions=['jinja2.ext.with_'])
except AttributeError:
template_env = Environment(
loader=PackageLoader('eli5', 'templates'))
template_env.globals.update(dict(zip=zip, numpy=np))
template_env.filters.update(dict(
weight_color=lambda w, w_range: format_hsl(weight_color_hsl(w, w_range)),
Expand Down Expand Up @@ -104,7 +107,7 @@ def format_as_html(explanation, # type: Explanation
abs(fw.weight) for fw in explanation.feature_importances.importances)
if explanation.feature_importances else 0,
target_weight_range=max_or_0(
get_weight_range(t.feature_weights) for t in targets
get_weight_range(t.feature_weights) for t in targets
if t.feature_weights is not None),
other_weight_range=max_or_0(
get_weight_range(other)
Expand Down
5 changes: 4 additions & 1 deletion eli5/sklearn/permutation_importance.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
clone,
is_classifier
)
from sklearn.metrics.scorer import check_scoring
try:
from sklearn.metrics.scorer import check_scoring
except ModuleNotFoundError:
from sklearn.metrics import check_scoring

from eli5.permutation_importance import get_score_importances
from eli5.sklearn.utils import pandas_available
Expand Down
5 changes: 4 additions & 1 deletion eli5/sklearn/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

import numpy as np
from sklearn.pipeline import Pipeline, FeatureUnion
from sklearn.feature_selection.base import SelectorMixin
try:
from sklearn.feature_selection.base import SelectorMixin
except ModuleNotFoundError:
from sklearn.feature_selection import SelectorMixin

from sklearn.preprocessing import (
MinMaxScaler,
Expand Down
15 changes: 15 additions & 0 deletions tests/test_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import jinja2
import sklearn


def test_import():
from packaging import version
if version.parse(jinja2.__version__) <= version.parse('3.0.3'):
raise ImportError('module "Jinja2" must be of a later version than "3.0.3".')
if version.parse(sklearn.__version__) < version.parse('1.0.2'):
raise ImportError('module "Jinja2" must be version "1.0.2" or later.')
Comment on lines +7 to +10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the goal of these checks? From the code above it seems that we do support older versions of these libraries? If we want to work only with versions specified here, it's better to specify this in setup.py.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the test file is probably not really needed, I omitted it and also slightly changed some other stuff in the PR for https://github.com/eli5-org/eli5/ (the sklearn issue for example was already resolved)

import eli5


if __name__ == '__main__':
test_import()