James McCool commited on
Commit
21ba9dc
·
1 Parent(s): bd643f8

Refactor lineup replacement logic in load_contest_file function

Browse files

- Simplified the lineup replacement process by removing try-except blocks and directly implementing sport-specific replacements for MLB, MMA, and GOLF.
- Enhanced the clarity and maintainability of the code while ensuring consistent handling of player roles across different sports.
- Maintained existing functionality while improving the robustness of the contest file loading process.

Files changed (1) hide show
  1. global_func/load_contest_file.py +6 -9
global_func/load_contest_file.py CHANGED
@@ -71,15 +71,12 @@ 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
- 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
  print(sport)
84
  print(cleaned_df.head(10))
85
  check_lineups = cleaned_df.copy()
 
71
 
72
  # Create the cleaned dataframe with just the essential columns
73
  cleaned_df = df[['BaseName', 'Lineup']]
74
+ if sport == 'MLB':
75
+ cleaned_df['Lineup'] = cleaned_df['Lineup'].replace([' P ', ' C ', '1B ', ' 2B ', ' 3B ', ' SS ', ' OF '], value=',', regex=True)
76
+ elif sport == 'MMA':
77
+ cleaned_df['Lineup'] = cleaned_df['Lineup'].replace([' P ', ' C ', '1B ', ' 2B ', ' 3B ', ' SS ', ' OF ', ' F ', 'F '], value=',', regex=True)
78
+ elif sport == 'GOLF':
79
+ cleaned_df['Lineup'] = cleaned_df['Lineup'].replace([' P ', ' C ', '1B ', ' 2B ', ' 3B ', ' SS ', ' OF ', ' G ', 'G '], value=',', regex=True)
 
 
 
80
  print(sport)
81
  print(cleaned_df.head(10))
82
  check_lineups = cleaned_df.copy()