{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Test notebook Titanic" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pathlib import Path\n", "\n", "import numpy as np\n", "import pandas as pd\n", "from IPython.utils.capture import capture_output\n", "from ipywidgets import widgets\n", "\n", "from ydata_profiling import ProfileReport\n", "from ydata_profiling.utils.cache import cache_file" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Read the Titanic Dataset\n", "file_name = cache_file(\n", " \"titanic.csv\",\n", " \"https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv\",\n", ")\n", "df = pd.read_csv(file_name)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Generate the Profiling Report (with progress bar)\n", "with capture_output() as out:\n", " profile = ProfileReport(\n", " df,\n", " title=\"Titanic Dataset\",\n", " html={\"style\": {\"full_width\": True}},\n", " progress_bar=True,\n", " lazy=False,\n", " )\n", "\n", "assert all(\n", " any(v in s.data[\"text/plain\"] for v in [\"%|\", \"FloatProgress\"]) for s in out.outputs\n", ")\n", "assert len(out.outputs) == 2" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Generate the Profiling Report (without progress bar)\n", "with capture_output() as out:\n", " profile = ProfileReport(\n", " df,\n", " title=\"Titanic Dataset\",\n", " html={\"style\": {\"full_width\": True}},\n", " progress_bar=False,\n", " lazy=False,\n", " )\n", "\n", "assert len(out.outputs) == 0" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Waiting on issue: https://github.com/computationalmodelling/nbval/issues/136\n", "\n", "# The Notebook Widgets Interface\n", "# with capture_output() as out:\n", "# profile.to_widgets()\n", "\n", "# assert len(out.outputs) == 2\n", "# assert out.outputs[0].data['text/plain'].startswith('Tab(children=(HTML(value=')\n", "# assert out.outputs[1].data['text/plain'] == ''\n", "# assert 'ydata-profiling' in out.outputs[1].data['text/html']" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Or use the HTML report in an iframe\n", "with capture_output() as out:\n", " profile.to_notebook_iframe()\n", "\n", "assert len(out.outputs) == 1\n", "assert out.outputs[0].data[\"text/plain\"] == \"\"" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.6" } }, "nbformat": 4, "nbformat_minor": 2 }