diff --git a/cyclops/evaluate/metrics/experimental/utils/types.py b/cyclops/evaluate/metrics/experimental/utils/types.py index e3543ddfc..96184c661 100644 --- a/cyclops/evaluate/metrics/experimental/utils/types.py +++ b/cyclops/evaluate/metrics/experimental/utils/types.py @@ -1,3 +1,5 @@ +# noqa: A005 + """Utilities for array-API compatibility.""" import builtins diff --git a/cyclops/monitor/utils.py b/cyclops/monitor/utils.py index 7584462ca..d990c5096 100644 --- a/cyclops/monitor/utils.py +++ b/cyclops/monitor/utils.py @@ -258,12 +258,12 @@ def get_args(obj: Any, kwargs: Dict[str, Any]) -> Dict[str, Any]: """ args = {} - for key in kwargs: + for key, value in kwargs.items(): if (inspect.isclass(obj) and key in inspect.signature(obj).parameters) or ( (inspect.ismethod(obj) or inspect.isfunction(obj)) and key in inspect.getfullargspec(obj).args ): - args[key] = kwargs[key] + args[key] = value return args diff --git a/cyclops/utils/profile.py b/cyclops/utils/profile.py index fd77ae7c2..1a5a9115e 100644 --- a/cyclops/utils/profile.py +++ b/cyclops/utils/profile.py @@ -1,3 +1,5 @@ +# noqa: A005 + """Useful functions for timing, profiling.""" import logging diff --git a/docs/source/examples/metrics.ipynb b/docs/source/examples/metrics.ipynb index cf2b10ba4..5e867b1f8 100644 --- a/docs/source/examples/metrics.ipynb +++ b/docs/source/examples/metrics.ipynb @@ -15,6 +15,8 @@ "metadata": {}, "outputs": [], "source": [ + "\"\"\"Imports.\"\"\"\n", + "\n", "import numpy as np\n", "import pandas as pd\n", "from datasets.arrow_dataset import Dataset\n", @@ -57,7 +59,7 @@ "outputs": [], "source": [ "df = breast_cancer_data.frame\n", - "df.describe().T" + "print(df.describe().T)" ] }, { @@ -222,7 +224,7 @@ "outputs": [], "source": [ "slice_spec = SliceSpec(spec_list, intersections=2)\n", - "slice_spec" + "print(slice_spec)" ] }, { @@ -316,15 +318,8 @@ " target_columns=\"target\",\n", " prediction_columns=\"preds_prob\",\n", ")\n", - "fairness_result" + "print(fairness_result)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/docs/source/examples/report.ipynb b/docs/source/examples/report.ipynb index 6312ba6f5..457f7572d 100644 --- a/docs/source/examples/report.ipynb +++ b/docs/source/examples/report.ipynb @@ -1,11 +1,21 @@ { "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Report Generation for Heart Failure Prediction\n", + "Here's an example to demonstrate how we can generate a report as we proceed through all the steps to train and evaluate a model. For this purpose, we are going to use Kaggle's heart prediction failure dataset and gradually populate the report with information about dataset, model and results." + ] + }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ + "\"\"\"Imports.\"\"\"\n", + "\n", "import copy\n", "import inspect\n", "import os\n", @@ -23,6 +33,7 @@ "from tqdm import tqdm\n", "\n", "from cyclops.data.slicer import SliceSpec\n", + "from cyclops.evaluate import evaluator\n", "from cyclops.evaluate.metrics import create_metric\n", "from cyclops.evaluate.metrics.experimental.metric_dict import MetricDict\n", "from cyclops.report import ModelCardReport\n", @@ -30,14 +41,6 @@ "from cyclops.report.utils import flatten_results_dict" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Report Generation for Heart Failure Prediction\n", - "Here's an example to demonstrate how we can generate a report as we proceed through all the steps to train and evaluate a model. For this purpose, we are going to use Kaggle's heart prediction failure dataset and gradually populate the report with information about dataset, model and results." - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -105,7 +108,7 @@ "metadata": {}, "outputs": [], "source": [ - "df.describe().T" + "print(df.describe().T)" ] }, { @@ -531,9 +534,6 @@ "metadata": {}, "outputs": [], "source": [ - "from cyclops.evaluate import evaluator\n", - "\n", - "\n", "# Create Dataset object\n", "heart_failure_data = Dataset.from_pandas(df_test)\n", "\n", @@ -557,24 +557,6 @@ ")" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "result" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "results_flat" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -878,7 +860,7 @@ ], "metadata": { "kernelspec": { - "display_name": "cyclops", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -892,9 +874,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.11" + "version": "3.10.12" } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/docs/source/tutorials/diabetes_130/readmission_prediction.ipynb b/docs/source/tutorials/diabetes_130/readmission_prediction.ipynb index bb7bdb3dd..61766e525 100644 --- a/docs/source/tutorials/diabetes_130/readmission_prediction.ipynb +++ b/docs/source/tutorials/diabetes_130/readmission_prediction.ipynb @@ -152,17 +152,6 @@ "variables = diabetes_130_data[\"variables\"]" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "metadata" - ] - }, { "cell_type": "code", "execution_count": null, diff --git a/docs/source/tutorials/diabetes_130/readmission_prediction_detectron.ipynb b/docs/source/tutorials/diabetes_130/readmission_prediction_detectron.ipynb index f34093832..e62cd2649 100644 --- a/docs/source/tutorials/diabetes_130/readmission_prediction_detectron.ipynb +++ b/docs/source/tutorials/diabetes_130/readmission_prediction_detectron.ipynb @@ -115,17 +115,6 @@ "variables = diabetes_130_data[\"variables\"]" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "metadata" - ] - }, { "cell_type": "code", "execution_count": null, @@ -749,7 +738,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.7" + "version": "3.10.12" } }, "nbformat": 4, diff --git a/tests/cyclops/evaluate/metrics/experimental/utils/test_ops.py b/tests/cyclops/evaluate/metrics/experimental/utils/test_ops.py index 65e61c18b..032b53733 100644 --- a/tests/cyclops/evaluate/metrics/experimental/utils/test_ops.py +++ b/tests/cyclops/evaluate/metrics/experimental/utils/test_ops.py @@ -189,19 +189,17 @@ def test_apply_to_nested_collections(self): }, } - for k in expected_result: + for k, v in expected_result.items(): assert k in result - if isinstance(expected_result[k], dict): - for kk in expected_result[k]: + if isinstance(v, dict): + for kk in v: assert kk in result[k] - assert anp.all(expected_result[k][kk] == result[k][kk]) - elif isinstance(expected_result[k], (tuple, list)): - assert all( - anp.all(a == b) for a, b in zip(result[k], expected_result[k]) - ) + assert anp.all(v[kk] == result[k][kk]) + elif isinstance(v, (tuple, list)): + assert all(anp.all(a == b) for a, b in zip(result[k], v)) else: - assert anp.all(expected_result[k] == result[k]) + assert anp.all(v == result[k]) class TestBincount: