|
7 | 7 | import streamlit as st |
8 | 8 | import streamlit.components.v1 as components |
9 | 9 | import plotly.graph_objects as go |
10 | | -import pandas as pd |
| 10 | + |
| 11 | +# Import pandas with error handling |
| 12 | +try: |
| 13 | + import pandas as pd |
| 14 | + PANDAS_AVAILABLE = True |
| 15 | +except ImportError: |
| 16 | + pd = None |
| 17 | + PANDAS_AVAILABLE = False |
| 18 | + st.warning("⚠️ pandas is not installed. Some features may not work correctly.") |
11 | 19 |
|
12 | 20 | # Import floating chat widget |
13 | 21 | try: |
@@ -1570,9 +1578,19 @@ def get_status_color(status: str) -> str: |
1570 | 1578 | }) |
1571 | 1579 |
|
1572 | 1580 | if table_data: |
1573 | | - import pandas as pd |
1574 | | - df = pd.DataFrame(table_data) |
1575 | | - st.dataframe(df, use_container_width=True, height=400) |
| 1581 | + if PANDAS_AVAILABLE and pd is not None: |
| 1582 | + try: |
| 1583 | + df = pd.DataFrame(table_data) |
| 1584 | + st.dataframe(df, use_container_width=True, height=400) |
| 1585 | + except Exception as e: |
| 1586 | + st.error(f"⚠️ Error creating DataFrame: {str(e)}") |
| 1587 | + # Fallback: display as list |
| 1588 | + for item in table_data: |
| 1589 | + st.json(item) |
| 1590 | + else: |
| 1591 | + st.warning("⚠️ pandas is not available. Displaying data as JSON:") |
| 1592 | + for item in table_data: |
| 1593 | + st.json(item) |
1576 | 1594 |
|
1577 | 1595 | # Show details in expander |
1578 | 1596 | st.markdown("### Item Details") |
@@ -1698,29 +1716,50 @@ def page_validation(): |
1698 | 1716 | if validators: |
1699 | 1717 | st.markdown("**Per-Validator Breakdown:**") |
1700 | 1718 |
|
1701 | | - # Create DataFrame for table display |
1702 | | - table_data = [] |
1703 | | - for v in validators: |
1704 | | - table_data.append({ |
1705 | | - "Validator": v.get("name", "Unknown"), |
1706 | | - "Total Checks": v.get("total_checks", 0), |
1707 | | - "Passed": v.get("passed", 0), |
1708 | | - "Failed": v.get("failed", 0), |
1709 | | - "Pass Rate": f"{v.get('pass_rate', 0.0):.1%}", |
1710 | | - "Status": "✅" if v.get("pass_rate", 0.0) >= 0.8 else "⚠️" if v.get("pass_rate", 0.0) >= 0.5 else "❌" |
1711 | | - }) |
1712 | | - |
1713 | | - df_validators = pd.DataFrame(table_data) |
1714 | | - st.dataframe(df_validators, use_container_width=True, hide_index=True) |
1715 | | - |
1716 | | - # Bar chart for pass rates |
1717 | | - if len(validators) > 0: |
1718 | | - st.markdown("**Pass Rate by Validator:**") |
1719 | | - chart_data = pd.DataFrame({ |
1720 | | - "Validator": [v.get("name", "Unknown") for v in validators], |
1721 | | - "Pass Rate": [v.get("pass_rate", 0.0) * 100 for v in validators] |
1722 | | - }) |
1723 | | - st.bar_chart(chart_data.set_index("Validator"), height=300) |
| 1719 | + # Check if pandas is available |
| 1720 | + if not PANDAS_AVAILABLE or pd is None: |
| 1721 | + st.error("⚠️ pandas is not available. Cannot display per-validator table.") |
| 1722 | + # Fallback: display as markdown table |
| 1723 | + st.markdown("| Validator | Total Checks | Passed | Failed | Pass Rate | Status |") |
| 1724 | + st.markdown("|-----------|--------------|--------|--------|-----------|--------|") |
| 1725 | + for v in validators: |
| 1726 | + pass_rate = v.get('pass_rate', 0.0) |
| 1727 | + status = "✅" if pass_rate >= 0.8 else "⚠️" if pass_rate >= 0.5 else "❌" |
| 1728 | + st.markdown(f"| {v.get('name', 'Unknown')} | {v.get('total_checks', 0)} | {v.get('passed', 0)} | {v.get('failed', 0)} | {pass_rate:.1%} | {status} |") |
| 1729 | + else: |
| 1730 | + try: |
| 1731 | + # Create DataFrame for table display |
| 1732 | + table_data = [] |
| 1733 | + for v in validators: |
| 1734 | + table_data.append({ |
| 1735 | + "Validator": v.get("name", "Unknown"), |
| 1736 | + "Total Checks": v.get("total_checks", 0), |
| 1737 | + "Passed": v.get("passed", 0), |
| 1738 | + "Failed": v.get("failed", 0), |
| 1739 | + "Pass Rate": f"{v.get('pass_rate', 0.0):.1%}", |
| 1740 | + "Status": "✅" if v.get("pass_rate", 0.0) >= 0.8 else "⚠️" if v.get("pass_rate", 0.0) >= 0.5 else "❌" |
| 1741 | + }) |
| 1742 | + |
| 1743 | + df_validators = pd.DataFrame(table_data) |
| 1744 | + st.dataframe(df_validators, use_container_width=True, hide_index=True) |
| 1745 | + |
| 1746 | + # Bar chart for pass rates |
| 1747 | + if len(validators) > 0: |
| 1748 | + st.markdown("**Pass Rate by Validator:**") |
| 1749 | + chart_data = pd.DataFrame({ |
| 1750 | + "Validator": [v.get("name", "Unknown") for v in validators], |
| 1751 | + "Pass Rate": [v.get("pass_rate", 0.0) * 100 for v in validators] |
| 1752 | + }) |
| 1753 | + st.bar_chart(chart_data.set_index("Validator"), height=300) |
| 1754 | + except Exception as pd_error: |
| 1755 | + st.error(f"⚠️ Error creating per-validator table: {str(pd_error)}") |
| 1756 | + # Fallback: display as markdown table |
| 1757 | + st.markdown("| Validator | Total Checks | Passed | Failed | Pass Rate | Status |") |
| 1758 | + st.markdown("|-----------|--------------|--------|--------|-----------|--------|") |
| 1759 | + for v in validators: |
| 1760 | + pass_rate = v.get('pass_rate', 0.0) |
| 1761 | + status = "✅" if pass_rate >= 0.8 else "⚠️" if pass_rate >= 0.5 else "❌" |
| 1762 | + st.markdown(f"| {v.get('name', 'Unknown')} | {v.get('total_checks', 0)} | {v.get('passed', 0)} | {v.get('failed', 0)} | {pass_rate:.1%} | {status} |") |
1724 | 1763 |
|
1725 | 1764 | # Failure reasons breakdown (expandable) |
1726 | 1765 | with st.expander("🔍 Detailed Failure Reasons"): |
@@ -1826,9 +1865,19 @@ def page_validation(): |
1826 | 1865 | "Retention Score": f"{item.get('retention_score', 0.0):.2f}" |
1827 | 1866 | }) |
1828 | 1867 |
|
1829 | | - import pandas as pd |
1830 | | - df = pd.DataFrame(table_data) |
1831 | | - st.dataframe(df, use_container_width=True, height=400) |
| 1868 | + if PANDAS_AVAILABLE and pd is not None: |
| 1869 | + try: |
| 1870 | + df = pd.DataFrame(table_data) |
| 1871 | + st.dataframe(df, use_container_width=True, height=400) |
| 1872 | + except Exception as e: |
| 1873 | + st.error(f"⚠️ Error creating DataFrame: {str(e)}") |
| 1874 | + # Fallback: display as list |
| 1875 | + for item in table_data: |
| 1876 | + st.json(item) |
| 1877 | + else: |
| 1878 | + st.warning("⚠️ pandas is not available. Displaying data as JSON:") |
| 1879 | + for item in table_data: |
| 1880 | + st.json(item) |
1832 | 1881 |
|
1833 | 1882 | # Show details in expander |
1834 | 1883 | st.markdown("### Item Details") |
|
0 commit comments