cwadayi commited on
Commit
a91379a
·
verified ·
1 Parent(s): 79a1bad

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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
- st.success(f"Found {len(df)} earthquakes matching your criteria.")
62
-
63
- # --- ROBUST FIX IS HERE ---
64
- # The API is inconsistent. Check for 'event_time', otherwise fall back to 'time'.
65
  if 'event_time' in df.columns:
66
- df['time'] = pd.to_datetime(df['event_time'])
67
  elif 'time' in df.columns:
68
- df['time'] = pd.to_datetime(df['time'])
 
 
 
69
  else:
70
- # If neither key is found, show an error and stop execution.
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