/
__init__.py
137 lines (113 loc) · 4.32 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# ----------------------------------------------------------------------------
# Copyright (C) 2021-2022 Deepchecks (https://www.deepchecks.com)
#
# This file is part of Deepchecks.
# Deepchecks is distributed under the terms of the GNU Affero General
# Public License (version 3 or later).
# You should have received a copy of the GNU Affero General Public License
# along with Deepchecks. If not, see <http://www.gnu.org/licenses/>.
# ----------------------------------------------------------------------------
#
"""Deepchecks."""
import os
import pathlib
import sys
import types
import warnings
from importlib._bootstrap import _init_module_attrs
import matplotlib
import plotly.io as pio
from deepchecks.analytics.anonymous_telemetry import \
send_anonymous_import_event
from deepchecks.core import (BaseCheck, BaseSuite, CheckFailure, CheckResult,
Condition, ConditionCategory, ConditionResult,
ModelOnlyBaseCheck, SingleDatasetBaseCheck,
SuiteResult, TrainTestBaseCheck)
# TODO: remove in further versions
from deepchecks.tabular import (Context, Dataset, ModelComparisonCheck,
ModelComparisonSuite, ModelOnlyCheck,
SingleDatasetCheck, Suite, TrainTestCheck)
from deepchecks.utils.ipython import is_notebook
__all__ = [
# core
'BaseCheck',
'SingleDatasetBaseCheck',
'TrainTestBaseCheck',
'ModelOnlyBaseCheck',
'CheckResult',
'CheckFailure',
'Condition',
'ConditionResult',
'ConditionCategory',
'BaseSuite',
'SuiteResult',
# tabular
'Dataset',
'Suite',
'Context',
'SingleDatasetCheck',
'TrainTestCheck',
'ModelOnlyCheck',
'ModelComparisonCheck',
'ModelComparisonSuite',
]
# Matplotlib has multiple backends. If we are in a context that does not support GUI (For example, during unit tests)
# we can't use a GUI backend. Thus we must use a non-GUI backend.
if not is_notebook():
matplotlib.use('Agg')
# We can't rely on that the user will have an active internet connection, thus we change the default backend to
# "notebook" If plotly detects the 'notebook-connected' backend.
# for more info, see: https://plotly.com/python/renderers/
pio_backends = pio.renderers.default.split('+')
if 'notebook_connected' in pio_backends:
pio_backends[pio_backends.index('notebook_connected')] = 'notebook'
pio.renderers.default = '+'.join(pio_backends)
# Set version info
try:
MODULE_DIR = pathlib.Path(__file__).absolute().parent
with open(os.path.join(MODULE_DIR, 'VERSION'), 'r', encoding='utf-8') as f:
__version__ = f.read().strip()
except: # pylint: disable=bare-except # noqa
# If version file can't be found, leave version empty
__version__ = ''
# Send an import event if not disabled
send_anonymous_import_event()
# ================================================================
warnings.filterwarnings(
action='once',
message=r'Ability to import.*',
category=DeprecationWarning,
module=r'deepchecks.*'
)
# NOTE:
# Code below is a temporary hack that exists only to provide backward compatibility
# and will be removed in the next versions.
__original_module__ = sys.modules[__name__]
class _SubstituteModule(types.ModuleType):
"""Substitute module type to provide backward compatibility."""
ROUTINES = (
'Dataset',
'Suite',
'Context',
'SingleDatasetCheck',
'TrainTestCheck',
'ModelOnlyCheck',
'ModelComparisonCheck',
'ModelComparisonSuite',
)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.__dict__.update(__original_module__.__dict__)
def __getattribute__(self, name):
routines = object.__getattribute__(self, 'ROUTINES')
if name in routines:
warnings.warn(
'Ability to import base tabular functionality from '
'the `deepchecks` package directly is deprecated, please '
'import from `deepchecks.tabular` instead',
DeprecationWarning
)
return object.__getattribute__(self, name)
__substitute_module__ = _SubstituteModule(__name__)
_init_module_attrs(__original_module__.__spec__, __substitute_module__, override=True)
sys.modules[__name__] = __substitute_module__