Spaces:
Build error
Build error
James McCool
commited on
Commit
·
f738bbd
1
Parent(s):
be3b754
Implement error handling for column dropping in data retrieval for Streamlit app
Browse files- Added try-except blocks to handle potential errors when dropping the '_id' column from various data tables.
- Ensured that if an error occurs, the original DataFrame is returned, maintaining data integrity across different tables.
- src/streamlit_app.py +52 -13
src/streamlit_app.py
CHANGED
|
@@ -102,31 +102,70 @@ def init_baselines():
|
|
| 102 |
df = pd.DataFrame(cursor)
|
| 103 |
|
| 104 |
if table == 'Bullpen_Data':
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
| 106 |
elif table == 'Hitter_Agg_Merge':
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
| 108 |
elif table == 'Hitter_Long_Merge':
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
| 110 |
elif table == 'Hitter_Short_Merge':
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
| 112 |
elif table == 'Pitcher_Agg_Merge':
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
| 114 |
elif table == 'Pitcher_Long_Merge':
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
| 116 |
elif table == 'Pitcher_Short_Merge':
|
| 117 |
-
|
|
|
|
|
|
|
|
|
|
| 118 |
elif table == 'Slate_Hitters_Merge':
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
| 120 |
elif table == 'Slate_Teams_Merge':
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
| 122 |
elif table == 'Starting_Pitchers':
|
| 123 |
-
|
|
|
|
|
|
|
|
|
|
| 124 |
elif table == 'True_AVG_Split':
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
| 126 |
elif table == 'Pitcher_Info':
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
| 128 |
elif table == 'Hitter_Info':
|
| 129 |
-
|
|
|
|
|
|
|
|
|
|
| 130 |
|
| 131 |
return bp_data, hitter_agg, hitter_long, hitter_short, pitcher_agg, pitcher_long, pitcher_short, slate_hitters, slate_team, starting_pitchers, true_avg_split, pitcher_info, hitter_info
|
| 132 |
|
|
|
|
| 102 |
df = pd.DataFrame(cursor)
|
| 103 |
|
| 104 |
if table == 'Bullpen_Data':
|
| 105 |
+
try:
|
| 106 |
+
bp_data = df.drop(columns = ['_id'])
|
| 107 |
+
except:
|
| 108 |
+
bp_data = df
|
| 109 |
elif table == 'Hitter_Agg_Merge':
|
| 110 |
+
try:
|
| 111 |
+
hitter_agg = df.drop(columns = ['_id'])
|
| 112 |
+
except:
|
| 113 |
+
hitter_agg = df
|
| 114 |
elif table == 'Hitter_Long_Merge':
|
| 115 |
+
try:
|
| 116 |
+
hitter_long = df.drop(columns = ['_id'])
|
| 117 |
+
except:
|
| 118 |
+
hitter_long = df
|
| 119 |
elif table == 'Hitter_Short_Merge':
|
| 120 |
+
try:
|
| 121 |
+
hitter_short = df.drop(columns = ['_id'])
|
| 122 |
+
except:
|
| 123 |
+
hitter_short = df
|
| 124 |
elif table == 'Pitcher_Agg_Merge':
|
| 125 |
+
try:
|
| 126 |
+
pitcher_agg = df.drop(columns = ['_id'])
|
| 127 |
+
except:
|
| 128 |
+
pitcher_agg = df
|
| 129 |
elif table == 'Pitcher_Long_Merge':
|
| 130 |
+
try:
|
| 131 |
+
pitcher_long = df.drop(columns = ['_id'])
|
| 132 |
+
except:
|
| 133 |
+
pitcher_long = df
|
| 134 |
elif table == 'Pitcher_Short_Merge':
|
| 135 |
+
try:
|
| 136 |
+
pitcher_short = df.drop(columns = ['_id'])
|
| 137 |
+
except:
|
| 138 |
+
pitcher_short = df
|
| 139 |
elif table == 'Slate_Hitters_Merge':
|
| 140 |
+
try:
|
| 141 |
+
slate_hitters = df.drop(columns = ['_id'])
|
| 142 |
+
except:
|
| 143 |
+
slate_hitters = df
|
| 144 |
elif table == 'Slate_Teams_Merge':
|
| 145 |
+
try:
|
| 146 |
+
slate_team = df.drop(columns = ['_id'])
|
| 147 |
+
except:
|
| 148 |
+
slate_team = df
|
| 149 |
elif table == 'Starting_Pitchers':
|
| 150 |
+
try:
|
| 151 |
+
starting_pitchers = df.drop(columns = ['_id'])
|
| 152 |
+
except:
|
| 153 |
+
starting_pitchers = df
|
| 154 |
elif table == 'True_AVG_Split':
|
| 155 |
+
try:
|
| 156 |
+
true_avg_split = df.drop(columns = ['_id'])
|
| 157 |
+
except:
|
| 158 |
+
true_avg_split = df
|
| 159 |
elif table == 'Pitcher_Info':
|
| 160 |
+
try:
|
| 161 |
+
pitcher_info = df.drop(columns = ['_id'])
|
| 162 |
+
except:
|
| 163 |
+
pitcher_info = df
|
| 164 |
elif table == 'Hitter_Info':
|
| 165 |
+
try:
|
| 166 |
+
hitter_info = df.drop(columns = ['_id'])
|
| 167 |
+
except:
|
| 168 |
+
hitter_info = df
|
| 169 |
|
| 170 |
return bp_data, hitter_agg, hitter_long, hitter_short, pitcher_agg, pitcher_long, pitcher_short, slate_hitters, slate_team, starting_pitchers, true_avg_split, pitcher_info, hitter_info
|
| 171 |
|