File size: 1,675 Bytes
e789e15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pandas as pd
import sweetviz as sv
from tools.dataframe import get_dataframe_summary
from typing import Tuple, Dict
import os
import tempfile


def explain_data(data_raw, n_sample= 10) -> str:
    """
    Tool: explain_data
    Description:
        Provides an extensive, narrative summary of a DataFrame including its shape, column types,
        missing value percentages, unique counts, sample rows, and (if not skipped) descriptive stats/info.

    Parameters:
        data_raw (dict): Raw data.
        n_sample (int, default=30): Number of rows to display.
        skip_stats (bool, default=False): If True, omit descriptive stats/info.

    LLM Guidance:
        Use when a detailed, human-readable explanation is needed—i.e., a full overview is preferred over a concise numerical summary.

    Returns:
        str: Detailed DataFrame summary.
    """
    print("    * Tool: explain_data")
    import pandas as pd

    result = get_dataframe_summary(
        pd.DataFrame(data_raw), n_sample=10, skip_stats=False
    )

    return result



def generate_sweetviz_report(
    data_raw: dict,
    target: str = None,
    report_name: str = "Report.html",
    report_directory: str = None,
    open_browser: bool = False,
) -> Tuple[str, Dict]:
    df = pd.DataFrame(data_raw)
    analysis = sv.analyze(df, target_feat=target)

    if report_directory is None:
        report_directory = tempfile.mkdtemp()
    report_path = os.path.join(report_directory, report_name)

    analysis.show_html(filepath=report_path, open_browser=open_browser)

    return (
        f"Press on the download report button at the bottom",
        {"report_path": report_path},
    )