Skip to content
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

Optional tempeh, conditional imports #338

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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
6 changes: 5 additions & 1 deletion aif360/algorithms/inprocessing/grid_search_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
"""
from logging import warning

import fairlearn.reductions as red
try:
import fairlearn.reductions as red
except ImportError as error:
warning("{}: GridSearchReduction will be unavailable. To install, run:\n"
"pip install 'aif360[Reductions]'".format(error))
import pandas as pd

from aif360.algorithms import Transformer
Expand Down
5 changes: 4 additions & 1 deletion aif360/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@
from aif360.datasets.meps_dataset_panel20_fy2015 import MEPSDataset20
from aif360.datasets.meps_dataset_panel21_fy2016 import MEPSDataset21
from aif360.datasets.regression_dataset import RegressionDataset
from aif360.datasets.law_school_gpa_dataset import LawSchoolGPADataset

import pkgutil
if pkgutil.find_loader("tempeh"):
from aif360.datasets.law_school_gpa_dataset import LawSchoolGPADataset
2 changes: 1 addition & 1 deletion aif360/metrics/mdss_classification_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from aif360.detectors.mdss.MDSS import MDSS

import pandas as pd
from sklearn.exceptions import deprecated
from sklearn.utils.deprecation import deprecated


class MDSSClassificationMetric(ClassificationMetric):
Expand Down
5 changes: 4 additions & 1 deletion aif360/sklearn/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@
from aif360.sklearn.datasets.openml_datasets import fetch_adult, fetch_german, fetch_bank
from aif360.sklearn.datasets.compas_dataset import fetch_compas
from aif360.sklearn.datasets.meps_datasets import fetch_meps
from aif360.sklearn.datasets.tempeh_datasets import fetch_lawschool_gpa

import pkgutil
if pkgutil.find_loader("tempeh"):
from aif360.sklearn.datasets.tempeh_datasets import fetch_lawschool_gpa
DanielRyszkaIBM marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 6 additions & 1 deletion aif360/sklearn/inprocessing/adversarial_debiasing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
from sklearn.preprocessing import LabelEncoder
from sklearn.utils import check_random_state
from sklearn.utils.validation import check_is_fitted
import tensorflow.compat.v1 as tf
try:
import tensorflow.compat.v1 as tf
except ImportError as error:
from logging import warning
warning("{}: AdversarialDebiasing will be unavailable. To install, run:\n"
"pip install 'aif360[AdversarialDebiasing]'".format(error))

from aif360.sklearn.utils import check_inputs, check_groups

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
available in the https://github.com/fairlearn/fairlearn library
licensed under the MIT Licencse, Copyright Microsoft Corporation
"""
import fairlearn.reductions as red
try:
import fairlearn.reductions as red
except ImportError as error:
from logging import warning
warning("{}: ExponentiatedGradientReduction will be unavailable. To install, run:\n"
"pip install 'aif360[Reductions]'".format(error))
from sklearn.base import BaseEstimator, ClassifierMixin, clone
from sklearn.preprocessing import LabelEncoder

Expand Down
7 changes: 6 additions & 1 deletion aif360/sklearn/inprocessing/grid_search_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
available in the https://github.com/fairlearn/fairlearn library
licensed under the MIT Licencse, Copyright Microsoft Corporation
"""
import fairlearn.reductions as red
try:
import fairlearn.reductions as red
except ImportError as error:
from logging import warning
warning("{}: GridSearchReduction will be unavailable. To install, run:\n"
"pip install 'aif360[Reductions]'".format(error))
from sklearn.base import BaseEstimator, ClassifierMixin, clone
from sklearn.preprocessing import LabelEncoder

Expand Down
2 changes: 1 addition & 1 deletion aif360/sklearn/metrics/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from sklearn.neighbors import NearestNeighbors
from sklearn.utils import check_X_y
from sklearn.utils.validation import column_or_1d
from sklearn.exceptions import deprecated
from sklearn.utils.deprecation import deprecated

from aif360.sklearn.utils import check_groups
from aif360.detectors.mdss.ScoringFunctions import BerkJones, Bernoulli
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
'Reductions': ['fairlearn==0.4.6'],
'FairAdapt':['rpy2'],
'notebooks': ['jupyter', 'tqdm', 'igraph[plotting]', 'lightgbm', 'seaborn', 'ipympl'],
'tempeh-datasets': ['tempeh'],
DanielRyszkaIBM marked this conversation as resolved.
Show resolved Hide resolved
}
extras['tests'] = reduce(lambda l1, l2: l1+l2, extras.values(), ['pytest>=3.5'])
extras['docs'] = ['sphinx<2', 'sphinx_rtd_theme']
Expand All @@ -40,11 +41,10 @@
python_requires='>=3.7',
install_requires=[
'numpy>=1.16',
'scipy>=1.2.0,<1.6.0',
'scipy>=1.2.0',
'pandas>=0.24.0',
'scikit-learn>=1.0',
'matplotlib',
'tempeh',
],
extras_require=extras,
package_data={'aif360': ['data/*', 'data/*/*', 'data/*/*/*']},
Expand Down