Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/deepchecks/MLChecks into 0.6.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ItayGabbay committed May 12, 2022
2 parents d6c0ce1 + c3df4f2 commit c4a2deb
Show file tree
Hide file tree
Showing 377 changed files with 10,452 additions and 3,166 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/lint.yml
Expand Up @@ -30,9 +30,13 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Run Pylint
run: make pylint

- name: Check import order
uses: jamescurtin/isort-action@master
with:
sortPaths: deepchecks/
docstring:
runs-on: ubuntu-latest
steps:
Expand Down
8 changes: 5 additions & 3 deletions .gitignore
Expand Up @@ -98,9 +98,11 @@ docs.error.log
# build folders of sphinx gallery
docs/source/user-guide/general/customizations/examples/
docs/source/user-guide/general/exporting_results/examples/
docs/source/checks_gallery/
docs/source/auto_tutorials/tabular
docs/source/auto_tutorials/vision
docs/source/checks_gallery/tabular/
docs/source/checks_gallery/vision/

docs/source/user-guide/tabular/auto_tutorials
docs/source/user-guide/vision/auto_tutorials

# build artifacts from running docs (vision and wandb export)
docs/source/tutorials/vision/*.html
Expand Down
1 change: 1 addition & 0 deletions .licenserc_fix.yaml
Expand Up @@ -32,6 +32,7 @@ header:
- 'deepchecks/base/resources'
- 'DESCRIPTION.rst'
- 'CITATION.cff'
- 'deepchecks/core/resources/requirejs.min.js'
comment: on-failure

dependency:
Expand Down
45 changes: 15 additions & 30 deletions deepchecks/__init__.py
Expand Up @@ -9,42 +9,27 @@
# ----------------------------------------------------------------------------
#
"""Deepchecks."""
import sys
import types
import os
import pathlib
import matplotlib
import plotly.io as pio
import sys
import types
import warnings
from importlib._bootstrap import _init_module_attrs

from deepchecks.utils.ipython import is_notebook
from deepchecks.core import (
BaseCheck,
BaseSuite,
CheckResult,
CheckFailure,
SuiteResult,
Condition,
ConditionResult,
ConditionCategory,
SingleDatasetBaseCheck,
TrainTestBaseCheck,
ModelOnlyBaseCheck
)
# TODO: remove in further versions
from deepchecks.tabular import (
Dataset,
Suite,
Context,
SingleDatasetCheck,
TrainTestCheck,
ModelOnlyCheck,
ModelComparisonCheck,
ModelComparisonSuite,
)
import matplotlib
import plotly.io as pio

from deepchecks.analytics.anonymous_telemetry import send_anonymous_import_event
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
Expand Down
1 change: 1 addition & 0 deletions deepchecks/analytics/anonymous_telemetry.py
Expand Up @@ -17,6 +17,7 @@
import os
import pathlib
import uuid

import deepchecks

MODULE_DIR = pathlib.Path(__file__).absolute().parent.parent
Expand Down
4 changes: 2 additions & 2 deletions deepchecks/checks.py
Expand Up @@ -15,8 +15,8 @@
"""
# flake8: noqa
import warnings
from deepchecks.tabular.checks import * # pylint: disable=wildcard-import

from deepchecks.tabular.checks import * # pylint: disable=wildcard-import

warnings.warn(
'Ability to import tabular checks from the `deepchecks.checks` '
Expand All @@ -38,7 +38,7 @@
'DataDuplicates',
'CategoryMismatchTrainTest',
'NewLabelTrainTest',
'LabelAmbiguity',
'ConflictingLabels',
'OutlierSampleDetection',

# methodology checks
Expand Down
19 changes: 7 additions & 12 deletions deepchecks/core/__init__.py
Expand Up @@ -12,24 +12,19 @@
Import objects to be available in parent deepchecks module.
"""
from .check_json import CheckFailureJson, CheckResultJson
from .check_result import CheckFailure, CheckResult
from .checks import (BaseCheck, DatasetKind, ModelOnlyBaseCheck,
SingleDatasetBaseCheck, TrainTestBaseCheck)
from .condition import Condition, ConditionCategory, ConditionResult
from .suite import BaseSuite, SuiteResult
from .condition import Condition, ConditionResult, ConditionCategory
from .check_result import (
CheckResult,
CheckFailure,
)
from .checks import (
DatasetKind,
BaseCheck,
SingleDatasetBaseCheck,
TrainTestBaseCheck,
ModelOnlyBaseCheck,
)

__all__ = [
'BaseCheck',
'CheckResult',
'CheckFailure',
'CheckFailureJson',
'CheckResultJson',
'Condition',
'ConditionResult',
'ConditionCategory',
Expand Down
122 changes: 122 additions & 0 deletions deepchecks/core/check_json.py
@@ -0,0 +1,122 @@
# ----------------------------------------------------------------------------
# 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/>.
# ----------------------------------------------------------------------------
#
"""Module containing the check results classes."""
# pylint: disable=super-init-not-called
import base64
import io
from typing import Dict, List, Union

import jsonpickle
import pandas as pd
import plotly

from deepchecks.core.check_result import CheckFailure, CheckResult
from deepchecks.core.condition import (Condition, ConditionCategory,
ConditionResult)
from deepchecks.utils.html import imagetag

__all__ = [
'CheckResultJson',
'CheckFailureJson',
]


class FakeCheck:
def __init__(self, metadata: Dict):
self._metadata = metadata

def metadata(self, *args, **kwargs): # pylint: disable=unused-argument
return self._metadata

def name(self):
return self._metadata['name']


class CheckResultJson(CheckResult):
"""Class which returns from a check with result that can later be used for automatic pipelines and display value.
Class containing the result of a check
The class stores the results and display of the check. Evaluating the result in an IPython console / notebook
will show the result display output.
Parameters
----------
json_data: Union[str, Dict]
Json data
"""

def __init__(self, json_dict: Union[str, Dict]):
if isinstance(json_dict, str):
json_dict = jsonpickle.loads(json_dict)

self.value = json_dict.get('value')
self.header = json_dict.get('header')
self.check = FakeCheck(json_dict.get('check'))

conditions_results_json = json_dict.get('conditions_results')
if conditions_results_json is not None:
self.conditions_results = []
for condition in conditions_results_json:
cond_res = ConditionResult(ConditionCategory[condition['Status']], condition['More Info'])
cond_res.set_name(condition['Condition'])
self.conditions_results.append(cond_res)
else:
self.conditions_results = None
json_display = json_dict.get('display')
self.display = []
if json_display is not None:
for record in json_display:
display_type, payload = record['type'], record['payload']
if display_type == 'html':
self.display.append(payload)
elif display_type == 'dataframe':
df = pd.DataFrame.from_records(payload)
self.display.append(df)
elif display_type == 'plotly':
plotly_json = io.StringIO(payload)
self.display.append(plotly.io.read_json(plotly_json))
elif display_type == 'plt':
self.display.append((f'<img src=\'data:image/png;base64,{payload}\'>'))
elif display_type == 'images':
assert isinstance(payload, list)
self.display.extend(
imagetag(base64.b64decode(it))
for it in payload
)
else:
raise ValueError(f'Unexpected type of display received: {display_type}')

def process_conditions(self) -> List[Condition]:
"""Conditions are already processed it is to prevent errors."""
pass


class CheckFailureJson(CheckFailure):
"""Class which holds a check run exception.
Parameters
----------
json_data: Union[str, Dict]
Json data
"""

def __init__(self, json_dict: Union[str, Dict]):
if isinstance(json_dict, str):
json_dict = jsonpickle.loads(json_dict)

self.header = json_dict.get('header')
self.check = FakeCheck(json_dict.get('check'))
self.exception = json_dict.get('exception')

def print_traceback(self):
"""Print the traceback of the failure."""
print(self.exception)

0 comments on commit c4a2deb

Please sign in to comment.