from pathlib import Path
import numpy as np
import pandas as pd
from IPython.utils.capture import capture_output
from ipywidgets import widgets
from ydata_profiling import ProfileReport
from ydata_profiling.utils.cache import cache_file
# Read the Titanic Dataset
file_name = cache_file(
"titanic.csv",
"https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv",
)
df = pd.read_csv(file_name)
# Generate the Profiling Report (with progress bar)
with capture_output() as out:
profile = ProfileReport(
df,
title="Titanic Dataset",
html={"style": {"full_width": True}},
progress_bar=True,
lazy=False,
)
assert all(
any(v in s.data["text/plain"] for v in ["%|", "FloatProgress"]) for s in out.outputs
)
assert len(out.outputs) == 2
# Generate the Profiling Report (without progress bar)
with capture_output() as out:
profile = ProfileReport(
df,
title="Titanic Dataset",
html={"style": {"full_width": True}},
progress_bar=False,
lazy=False,
)
assert len(out.outputs) == 0
# Waiting on issue: https://github.com/computationalmodelling/nbval/issues/136
# The Notebook Widgets Interface
# with capture_output() as out:
# profile.to_widgets()
# assert len(out.outputs) == 2
# assert out.outputs[0].data['text/plain'].startswith('Tab(children=(HTML(value=')
# assert out.outputs[1].data['text/plain'] == '<IPython.core.display.HTML object>'
# assert 'ydata-profiling' in out.outputs[1].data['text/html']
# Or use the HTML report in an iframe
with capture_output() as out:
profile.to_notebook_iframe()
assert len(out.outputs) == 1
assert out.outputs[0].data["text/plain"] == "<IPython.core.display.HTML object>"