{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Test notebook Meteorites" ] }, { "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", "import requests\n", "from IPython.display import display\n", "from IPython.utils.capture import capture_output\n", "\n", "import ydata_profiling\n", "from ydata_profiling.utils.cache import cache_file" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "file_name = cache_file(\n", " \"meteorites.csv\",\n", " \"https://data.nasa.gov/api/views/gh4g-9sfh/rows.csv?accessType=DOWNLOAD\",\n", ")\n", "\n", "df = pd.read_csv(file_name)\n", "\n", "# Note: Pandas does not support dates before 1880, so we ignore these for this analysis\n", "df[\"year\"] = pd.to_datetime(df[\"year\"], errors=\"coerce\")\n", "\n", "# Example: Constant variable\n", "df[\"source\"] = \"NASA\"\n", "\n", "# Example: Boolean variable\n", "df[\"boolean\"] = np.random.choice([True, False], df.shape[0])\n", "\n", "# Example: Mixed with base types\n", "df[\"mixed\"] = np.random.choice([1, \"A\"], df.shape[0])\n", "\n", "# Example: Highly correlated variables\n", "df[\"reclat_city\"] = df[\"reclat\"] + np.random.normal(scale=5, size=(len(df)))\n", "\n", "# Example: Duplicate observations\n", "duplicates_to_add = pd.DataFrame(df.iloc[0:10])\n", "duplicates_to_add[\"name\"] = duplicates_to_add[\"name\"] + \" copy\"\n", "\n", "df = pd.concat([df, duplicates_to_add], ignore_index=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Inline report without saving\n", "with capture_output() as out:\n", " pr = df.profile_report(\n", " sort=None,\n", " html={\"style\": {\"full_width\": True}},\n", " progress_bar=False,\n", " minimal=True,\n", " )\n", " display(pr)\n", "\n", "assert len(out.outputs) == 2\n", "assert out.outputs[0].data[\"text/plain\"] == \"\"\n", "assert out.outputs[1].data[\"text/plain\"] == \"\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# There should also 2 progress bars in minimal mode\n", "with capture_output() as out:\n", " pfr = df.profile_report(\n", " html={\"style\": {\"full_width\": True}},\n", " minimal=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": [ "# Write to a file\n", "with capture_output() as out:\n", " pfr.to_file(\"/tmp/example.html\")\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": [ "# Print existing ProfileReport object inline\n", "with capture_output() as out:\n", " display(pfr)\n", "\n", "assert len(out.outputs) == 2\n", "assert out.outputs[0].data[\"text/plain\"] == \"\"\n", "assert out.outputs[1].data[\"text/plain\"] == \"\"" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.7.4" } }, "nbformat": 4, "nbformat_minor": 2 }