"""Logic for the **Debug Data** tab.""" from __future__ import annotations from .state import app_state __all__ = ["debug_data_structure"] def debug_data_structure() -> str: if app_state["clustered_df"] is None: return "

❌ No data loaded

" df = app_state["clustered_df"] n_rows = len(df) n_cols = len(df.columns) # Check for both naming patterns has_fine_clusters = ("property_description_fine_cluster_id" in df.columns or "fine_cluster_id" in df.columns) has_coarse_clusters = ("property_description_coarse_cluster_id" in df.columns or "coarse_cluster_id" in df.columns) sample_rows = min(3, len(df)) sample_data = df.head(sample_rows).to_html( escape=False, classes="table table-striped", table_id="debug-table", ) html = f"""

🐛 Data Structure Debug Info

Basic Statistics

Available Columns

    """ for col in sorted(df.columns): unique_values = df[col].nunique() if df[col].dtype == "object" else "N/A" html += f"
  • {col} - {df[col].dtype} (unique values: {unique_values})
  • " html += f"""

Sample Data (First {sample_rows} rows)

{sample_data}
""" return html