-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy path__init__.py
More file actions
101 lines (85 loc) · 3.1 KB
/
Copy path__init__.py
File metadata and controls
101 lines (85 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
"""
This module implements the create_diff_report([df1, df2]) function.
"""
import warnings
from typing import Any, Dict, List, Optional, Union
from collections import defaultdict
import pandas as pd
from bokeh.resources import INLINE
from jinja2 import Environment, PackageLoader
from .diff_formatter import format_diff_report
from ..configs import Config
from ..create_report.report import Report
__all__ = ["create_diff_report"]
ENV_LOADER = Environment(
loader=PackageLoader("dataprep", "eda/create_diff_report/templates"),
)
def create_diff_report(
df_list: Union[List[pd.DataFrame], Dict[str, pd.DataFrame]],
target: Optional[str] = None,
config: Optional[Dict[str, Any]] = None,
display: Optional[List[str]] = None,
title: Optional[str] = "DataPrep Report",
mode: Optional[str] = "basic",
progress: bool = True,
) -> Report:
"""
This function is to generate and render elements in a report object given multiple dataframes.
Parameters
----------
df_list
The DataFrames for which data are calculated.
target
Target feature to be compared against all other columns.
config
A dictionary for configuring the visualizations
E.g. config={"hist.bins": 20}
display
The list that contains the names of plots user wants to display,
E.g. display = ["bar", "hist"]
Without user's specifications, the default is "auto"
title: Optional[str], default "DataPrep Report"
The title of the report, which will be shown on the navigation bar.
mode: Optional[str], default "basic"
This controls what type of report to be generated.
Currently only the 'basic' is fully implemented.
progress
Whether to show the progress bar.
Examples
--------
from dataprep.datasets import load_dataset
from dataprep.eda import create_diff_report
df_train = load_dataset('house_prices_train')
df_test = load_dataset('house_prices_test')
create_diff_report([df_train, df_test]) # show in browser on jupyter notebook
"""
# pylint: disable=too-many-arguments
_suppress_warnings()
cfg = Config.from_dict(display, config)
components = format_diff_report(df_list, cfg, mode, progress, target)
dict_stats = defaultdict(list)
for comps in components["dfs"]:
for key, value in comps["overview"][0].items():
if value is not None:
dict_stats[key].append(value)
context = {
"resources": INLINE.render(),
"title": title,
"stats": dict_stats,
"components": components,
"is_diff_report": True,
"df_labels": cfg.diff.label,
"legend_labels": components["legend_lables"],
}
template_base = ENV_LOADER.get_template("base.html")
report = template_base.render(context=context, zip=zip)
return Report(report)
def _suppress_warnings() -> None:
"""
suppress warnings in create_diff_report
"""
warnings.filterwarnings(
"ignore",
"The default value of regex will change from True to False in a future version",
category=FutureWarning,
)