Skip to content

Commit 8151e3b

Browse files
committed
Merge branch 'master' into gaugup/AddPython3.10
2 parents 0b8696b + bad94ac commit 8151e3b

48 files changed

Lines changed: 237 additions & 119 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# This workflow will lint python code with flake8 and flake8-nb.
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3+
4+
name: Python linting
5+
6+
on:
7+
push:
8+
branches: [ master ]
9+
pull_request:
10+
branches: [ master ]
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Set up Python 3.7
19+
uses: actions/setup-python@v2
20+
with:
21+
python-version: 3.7
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install -r requirements-linting.txt
26+
- name: Check sorted python imports using isort
27+
run: |
28+
isort . -c
29+
- name: Lint code with flake8
30+
run: |
31+
# stop the build if there are Python syntax errors or undefined names
32+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
33+
# The GitHub editor is 127 chars wide.
34+
flake8 . --count --max-complexity=30 --max-line-length=127 --statistics
35+
# Check for cyclometric complexity for specific files where this metric has been
36+
# reduced to ten and below
37+
flake8 dice_ml/data_interfaces/ --count --max-complexity=10 --max-line-length=127
38+
- name: Lint notebooks with flake8_nb
39+
run: |
40+
# stop the build if there are flake8 errors in notebooks
41+
flake8_nb docs/source/notebooks/ --statistics --max-line-length=127
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Python Package using Conda
2+
3+
on: [push]
4+
5+
jobs:
6+
build-linux:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
max-parallel: 5
10+
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: Set up Python 3.8
14+
uses: actions/setup-python@v2
15+
with:
16+
python-version: 3.8
17+
- name: Add conda to system path
18+
run: |
19+
# $CONDA is an environment variable pointing to the root of the miniconda directory
20+
echo $CONDA/bin >> $GITHUB_PATH
21+
- name: Install core dependencies
22+
run: |
23+
conda env update --file environment.yml --name base
24+
- name: Install deep learning dependencies
25+
run: |
26+
conda env update --file environment-deeplearning.yml --name base
27+
- name: Test with pytest
28+
run: |
29+
conda install pytest ipython jupyter nbformat pytest-mock
30+
31+
pytest

.github/workflows/pythonpackage.yml

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
22
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
33

4-
name: Python package
4+
name: Python package test
55

66
on:
77
push:
@@ -24,25 +24,18 @@ jobs:
2424
uses: actions/setup-python@v1
2525
with:
2626
python-version: ${{ matrix.python-version }}
27-
- name: Install dependencies
27+
- name: Upgrade pip
2828
run: |
2929
python -m pip install --upgrade pip
30-
pip install -r requirements-test.txt
30+
- name: Install core dependencies
31+
run: |
3132
pip install -r requirements.txt
32-
pip install -r requirements-deeplearning.txt
33-
- name: Lint code with flake8
33+
- name: Install deep learning dependencies
3434
run: |
35-
# stop the build if there are Python syntax errors or undefined names
36-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
37-
# The GitHub editor is 127 chars wide.
38-
flake8 . --count --max-complexity=30 --max-line-length=127 --statistics
39-
# Check for cyclometric complexity for specific files where this metric has been
40-
# reduced to ten and below
41-
flake8 dice_ml/data_interfaces/ --count --max-complexity=10 --max-line-length=127
42-
- name: Lint notebooks with flake8_nb
35+
pip install -r requirements-deeplearning.txt
36+
- name: Install test dependencies
4337
run: |
44-
# stop the build if there are flake8 errors in notebooks
45-
flake8_nb docs/source/notebooks/ --statistics --max-line-length=127
38+
pip install -r requirements-test.txt
4639
- name: Test with pytest
4740
run: |
4841
# pytest

CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# dice-ml package
2+
/dice_ml @gaugup @amit-sharma

dice_ml/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from .data import Data
2-
from .model import Model
32
from .dice import Dice
3+
from .model import Model
44

55
__all__ = ["Data",
66
"Model",

dice_ml/counterfactual_explanations.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import json
2-
import jsonschema
32
import os
43

5-
from dice_ml.diverse_counterfactuals import CounterfactualExamples
6-
from dice_ml.utils.exception import UserConfigValidationException
7-
from dice_ml.diverse_counterfactuals import _DiverseCFV2SchemaConstants
4+
import jsonschema
5+
86
from dice_ml.constants import _SchemaVersions
7+
from dice_ml.diverse_counterfactuals import (CounterfactualExamples,
8+
_DiverseCFV2SchemaConstants)
9+
from dice_ml.utils.exception import UserConfigValidationException
910

1011

1112
class _CommonSchemaConstants:

dice_ml/data_interfaces/private_data_interface.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""Module containing meta data information about private data."""
22

3-
import sys
4-
import pandas as pd
5-
import numpy as np
63
import collections
74
import logging
5+
import sys
6+
7+
import numpy as np
8+
import pandas as pd
89

910
from dice_ml.data_interfaces.base_data_interface import _BaseData
1011

dice_ml/data_interfaces/public_data_interface.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
"""Module containing all required information about the interface between raw (or transformed)
22
public data and DiCE explainers."""
33

4-
import pandas as pd
5-
import numpy as np
64
import logging
75
from collections import defaultdict
86

7+
import numpy as np
8+
import pandas as pd
9+
910
from dice_ml.data_interfaces.base_data_interface import _BaseData
10-
from dice_ml.utils.exception import SystemException, UserConfigValidationException
11+
from dice_ml.utils.exception import (SystemException,
12+
UserConfigValidationException)
1113

1214

1315
class PublicData(_BaseData):
@@ -258,7 +260,7 @@ def get_valid_feature_range(self, feature_range_input, normalized=True):
258260
"""
259261
feature_range = {}
260262

261-
for idx, feature_name in enumerate(self.feature_names):
263+
for _, feature_name in enumerate(self.feature_names):
262264
feature_range[feature_name] = []
263265
if feature_name in self.continuous_feature_names:
264266
max_value = self.data_df[feature_name].max()

dice_ml/dice.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
such as RandomSampling, DiCEKD or DiCEGenetic"""
44

55
from dice_ml.constants import BackEndTypes, SamplingStrategy
6-
from dice_ml.utils.exception import UserConfigValidationException
7-
from dice_ml.explainer_interfaces.explainer_base import ExplainerBase
86
from dice_ml.data_interfaces.private_data_interface import PrivateData
7+
from dice_ml.explainer_interfaces.explainer_base import ExplainerBase
8+
from dice_ml.utils.exception import UserConfigValidationException
99

1010

1111
class Dice(ExplainerBase):
@@ -67,12 +67,14 @@ def decide(model_interface, method):
6767

6868
elif model_interface.backend == BackEndTypes.Tensorflow1:
6969
# pretrained Keras Sequential model with Tensorflow 1.x backend
70-
from dice_ml.explainer_interfaces.dice_tensorflow1 import DiceTensorFlow1
70+
from dice_ml.explainer_interfaces.dice_tensorflow1 import \
71+
DiceTensorFlow1
7172
return DiceTensorFlow1
7273

7374
elif model_interface.backend == BackEndTypes.Tensorflow2:
7475
# pretrained Keras Sequential model with Tensorflow 2.x backend
75-
from dice_ml.explainer_interfaces.dice_tensorflow2 import DiceTensorFlow2
76+
from dice_ml.explainer_interfaces.dice_tensorflow2 import \
77+
DiceTensorFlow2
7678
return DiceTensorFlow2
7779

7880
elif model_interface.backend == BackEndTypes.Pytorch:

dice_ml/diverse_counterfactuals.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import pandas as pd
21
import copy
32
import json
3+
4+
import pandas as pd
5+
6+
from dice_ml.constants import ModelTypes, _SchemaVersions
47
from dice_ml.utils.serialize import DummyDataInterface
5-
from dice_ml.constants import _SchemaVersions, ModelTypes
68

79

810
class _DiverseCFV1SchemaConstants:
@@ -115,6 +117,7 @@ def _visualize_internal(self, display_sparse_df=True, show_only_changes=False,
115117

116118
def visualize_as_dataframe(self, display_sparse_df=True, show_only_changes=False):
117119
from IPython.display import display
120+
118121
# original instance
119122
print('Query instance (original outcome : %i)' % round(self.test_pred))
120123
display(self.test_instance_df) # works only in Jupyter notebook

0 commit comments

Comments
 (0)