James McCool
commited on
Commit
·
5c9b782
1
Parent(s):
ab18789
Enhance load_contest_file function to improve error handling and user feedback
Browse files- Refactored the load_contest_file function to include a try-except block for better error management when loading files.
- Added a specific error message for unsupported file types, ensuring users are informed about acceptable formats (CSV or Excel).
- Streamlined the logic for loading DataFrames directly, enhancing usability for users working with different data formats.
global_func/load_contest_file.py
CHANGED
@@ -5,15 +5,17 @@ def load_contest_file(upload, sport):
|
|
5 |
pos_values = ['P', 'C', '1B', '2B', '3B', 'SS', 'OF']
|
6 |
if upload is not None:
|
7 |
try:
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
13 |
raw_df = upload
|
14 |
-
else:
|
15 |
-
st.error('Please upload either a CSV or Excel file')
|
16 |
-
return None
|
17 |
|
18 |
df = raw_df[['EntryId', 'EntryName', 'TimeRemaining', 'Points', 'Lineup', 'Player', 'Roster Position', '%Drafted', 'FPTS']]
|
19 |
df = df.rename(columns={'Roster Position': 'Pos', '%Drafted': 'Own'})
|
|
|
5 |
pos_values = ['P', 'C', '1B', '2B', '3B', 'SS', 'OF']
|
6 |
if upload is not None:
|
7 |
try:
|
8 |
+
try:
|
9 |
+
|
10 |
+
if upload.name.endswith('.csv'):
|
11 |
+
raw_df = pd.read_csv(upload)
|
12 |
+
elif upload.name.endswith(('.xls', '.xlsx')):
|
13 |
+
raw_df = pd.read_excel(upload)
|
14 |
+
else:
|
15 |
+
st.error('Please upload either a CSV or Excel file')
|
16 |
+
return None
|
17 |
+
except:
|
18 |
raw_df = upload
|
|
|
|
|
|
|
19 |
|
20 |
df = raw_df[['EntryId', 'EntryName', 'TimeRemaining', 'Points', 'Lineup', 'Player', 'Roster Position', '%Drafted', 'FPTS']]
|
21 |
df = df.rename(columns={'Roster Position': 'Pos', '%Drafted': 'Own'})
|