Update src/streamlit_app.py
Browse files- src/streamlit_app.py +13 -7
src/streamlit_app.py
CHANGED
|
@@ -58,19 +58,25 @@ if search_button:
|
|
| 58 |
df = fetch_earthquakes(start_date, end_date, min_magnitude)
|
| 59 |
|
| 60 |
if df is not None and not df.empty:
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
# The API is inconsistent. Check for 'event_time', otherwise fall back to 'time'.
|
| 65 |
if 'event_time' in df.columns:
|
| 66 |
-
|
| 67 |
elif 'time' in df.columns:
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
| 69 |
else:
|
| 70 |
-
# If
|
| 71 |
st.error("Data format error: Could not find a valid time column in the API response.")
|
|
|
|
|
|
|
| 72 |
st.stop()
|
| 73 |
|
|
|
|
|
|
|
| 74 |
df['magnitude'] = df['mag'].astype(float)
|
| 75 |
df['depth'] = df['depth'].astype(float)
|
| 76 |
|
|
|
|
| 58 |
df = fetch_earthquakes(start_date, end_date, min_magnitude)
|
| 59 |
|
| 60 |
if df is not None and not df.empty:
|
| 61 |
+
# --- DIAGNOSTIC FIX IS HERE ---
|
| 62 |
+
# This logic now includes a debugging message to reveal the available columns.
|
| 63 |
+
time_col = None
|
|
|
|
| 64 |
if 'event_time' in df.columns:
|
| 65 |
+
time_col = 'event_time'
|
| 66 |
elif 'time' in df.columns:
|
| 67 |
+
time_col = 'time'
|
| 68 |
+
|
| 69 |
+
if time_col:
|
| 70 |
+
df['time'] = pd.to_datetime(df[time_col])
|
| 71 |
else:
|
| 72 |
+
# If no time column is found, print the available columns for debugging.
|
| 73 |
st.error("Data format error: Could not find a valid time column in the API response.")
|
| 74 |
+
st.warning("The API returned data, but the column names were not as expected.")
|
| 75 |
+
st.write("**Available columns found in the data:**", df.columns.tolist())
|
| 76 |
st.stop()
|
| 77 |
|
| 78 |
+
# --- The rest of the script continues as before ---
|
| 79 |
+
st.success(f"Found {len(df)} earthquakes matching your criteria.")
|
| 80 |
df['magnitude'] = df['mag'].astype(float)
|
| 81 |
df['depth'] = df['depth'].astype(float)
|
| 82 |
|