Skip to content

🧱 ExportableMixin Utility

ExportMixin

Methods:

  • export
  • to_dataframe

    Convert the response data collection to a Pandas DataFrame.

  • summary

    Print and optionally save an analytics summary of the dataset.

export

export(
    filename: str = "doge_data", format: str = "csv"
) -> Path

to_dataframe

to_dataframe() -> DataFrame

Convert the response data collection to a Pandas DataFrame.

Returns:

  • DataFrame

summary

summary(verbose: bool = False, save_as: str = None)

Print and optionally save an analytics summary of the dataset.

Parameters:

  • verbose

    (bool, default: False ) –

    If True, print a head preview of the data.

  • save_as

    (str, default: None ) –

    Path to save the summary text (e.g. "summary.md" or "report.txt").


🔁 Utility Functions

handle_dict

handle_dict

handle_dict(obj)
Source code in src/pydoge_api/utils/exporter.py
118
119
120
121
122
def handle_dict(obj):
    if isinstance(obj, dict) and not hasattr(obj, "export"):
        new_obj = DictExportable(**obj)
        return new_obj
    return obj

This ensures that even raw dict responses support .export().


DictExportable

DictExportable

A dict subclass with .export() support

Methods:

  • summary

    Print and optionally save an analytics summary of the dataset.

  • to_dataframe

    Convert the response data collection to a Pandas DataFrame.

summary

summary(verbose: bool = False, save_as: str = None)

Print and optionally save an analytics summary of the dataset.

Parameters:

  • verbose

    (bool, default: False ) –

    If True, print a head preview of the data.

  • save_as

    (str, default: None ) –

    Path to save the summary text (e.g. "summary.md" or "report.txt").

Source code in src/pydoge_api/utils/exporter.py
 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
102
103
104
105
106
107
108
109
110
111
112
def summary(self, verbose: bool = False, save_as: str = None):
    """
    Print and optionally save an analytics summary of the dataset.

    Parameters
    ----------
    verbose : bool
        If True, print a head preview of the data.
    save_as : str, optional
        Path to save the summary text (e.g. "summary.md" or "report.txt").
    """

    df = self.to_dataframe()
    out = StringIO()

    def p(text=""):
        print(text, file=out)

    p("📊 PyDoge Data Summary")
    p("=" * 40)
    p(f"🧾 Rows       : {df.shape[0]}")
    p(f"🧬 Columns    : {df.shape[1]}")
    p(f"🕳️  Total NaNs : {df.isnull().sum().sum()}\n")

    p("📑 Column Data Types:")
    p(df.dtypes.to_string())
    p("")

    nulls = df.isnull().sum()
    nulls = nulls[nulls > 0]
    p("📉 Nulls by Column:")
    p(nulls.to_string() if not nulls.empty else "✅ No null values detected")
    p("")

    numeric_cols = df.select_dtypes(include="number").columns
    if not numeric_cols.empty:
        p("📈 Numeric Column Stats:")
        stats = df[numeric_cols].agg(["count", "mean", "std", "min", "max"]).T
        stats = stats[["count", "mean", "std", "min", "max"]]
        p(stats.round(2).to_string())
        p("")

    cat_cols = df.select_dtypes(include="object").columns
    if not cat_cols.empty:
        p("🔠 Top Categories:")
        for col in cat_cols:
            top = df[col].value_counts().head(3)
            p(f"\n[{col}]")
            p(top.to_string())

    if verbose:
        p("\n📋 Sample Preview:")
        p(df.head().to_string())

    # Print to terminal
    print(out.getvalue())

    # Optionally save to file
    if save_as:
        with open(save_as, "w", encoding="utf-8") as f:
            f.write(out.getvalue())

to_dataframe

to_dataframe() -> DataFrame

Convert the response data collection to a Pandas DataFrame.

Returns:

  • DataFrame
Source code in src/pydoge_api/utils/exporter.py
42
43
44
45
46
47
48
49
50
def to_dataframe(self) -> pd.DataFrame:
    """
    Convert the response data collection to a Pandas DataFrame.

    Returns
    -------
    pd.DataFrame
    """
    return pd.DataFrame(self._get_collection())

A subclass of dict that supports .export(), .to_dataframe(), .summary(). Used when output_pydantic=False.