James McCool commited on
Commit
e37ddff
·
1 Parent(s): 0a19512

Enhance error handling for lineup replacements in load_contest_file function

Browse files

- Added try-except blocks to handle exceptions during lineup replacements, ensuring robustness across different sports.
- Implemented specific replacements for MLB, MMA, and GOLF to maintain data integrity and improve flexibility in player role assignments.
- Maintained existing functionality while enhancing error resilience in the contest file loading process.

Files changed (1) hide show
  1. global_func/load_contest_file.py +9 -1
global_func/load_contest_file.py CHANGED
@@ -71,7 +71,15 @@ def load_contest_file(upload, helper = None, sport = None):
71
 
72
  # Create the cleaned dataframe with just the essential columns
73
  cleaned_df = df[['BaseName', 'Lineup']]
74
- cleaned_df['Lineup'] = cleaned_df['Lineup'].replace(pos_list, value=',', regex=True)
 
 
 
 
 
 
 
 
75
  check_lineups = cleaned_df.copy()
76
  if sport == 'MLB':
77
  cleaned_df[['Remove', '1B', '2B', '3B', 'C', 'OF1', 'OF2', 'OF3', 'P1', 'P2', 'SS']] = cleaned_df['Lineup'].str.split(',', expand=True)
 
71
 
72
  # Create the cleaned dataframe with just the essential columns
73
  cleaned_df = df[['BaseName', 'Lineup']]
74
+ try:
75
+ cleaned_df['Lineup'] = cleaned_df['Lineup'].replace(pos_list, value=',', regex=True)
76
+ except:
77
+ if sport == 'MLB':
78
+ cleaned_df['Lineup'] = cleaned_df['Lineup'].replace([' P ', ' C ', '1B ', ' 2B ', ' 3B ', ' SS ', ' OF '], value=',', regex=True)
79
+ elif sport == 'MMA':
80
+ cleaned_df['Lineup'] = cleaned_df['Lineup'].replace([' F ', 'F '], value=',', regex=True)
81
+ elif sport == 'GOLF':
82
+ cleaned_df['Lineup'] = cleaned_df['Lineup'].replace([' G ', 'G '], value=',', regex=True)
83
  check_lineups = cleaned_df.copy()
84
  if sport == 'MLB':
85
  cleaned_df[['Remove', '1B', '2B', '3B', 'C', 'OF1', 'OF2', 'OF3', 'P1', 'P2', 'SS']] = cleaned_df['Lineup'].str.split(',', expand=True)