James McCool commited on
Commit
dca21a5
·
1 Parent(s): 2f8b929

Enhance lineup processing in hedging_preset.py by adding checks for empty DataFrames before generating lineups. This update prevents errors when no lineups are available and improves the clarity of debug messages related to lineup generation.

Browse files
Files changed (1) hide show
  1. global_func/hedging_preset.py +17 -12
global_func/hedging_preset.py CHANGED
@@ -51,16 +51,19 @@ def hedging_preset(portfolio: pd.DataFrame, lineup_target: int, projections_file
51
  )
52
 
53
  removed_df = working_df[remove_mask]
54
- print(removed_df.head(10))
55
  locked_df = working_df[lock_mask]
56
- print(locked_df.head(10))
57
 
58
  removed_lineups = small_field_preset(removed_df, math.ceil(lineup_target / (list_size * 3)), excluded_cols)
59
  print(len(removed_lineups))
60
- locked_lineups = large_field_preset(locked_df, math.ceil(lineup_target / (list_size * 3)), excluded_cols)
61
- print(len(locked_lineups))
62
-
63
- concat_portfolio = pd.concat([concat_portfolio, removed_lineups, locked_lineups])
 
 
 
 
 
64
 
65
  for team in top_owned_teams:
66
  working_df = portfolio.copy()
@@ -68,11 +71,13 @@ def hedging_preset(portfolio: pd.DataFrame, lineup_target: int, projections_file
68
  teams_df = working_df[working_df['Stack'] == team]
69
 
70
  removed_lineups = small_field_preset(removed_df, math.ceil(lineup_target / (list_size * 3)), excluded_cols)
71
- print(len(removed_lineups))
72
- print(removed_lineups.head(10))
73
- team_lineups = large_field_preset(teams_df, math.ceil(lineup_target / (list_size * 3)), excluded_cols)
74
- print(len(team_lineups))
75
- print(team_lineups.head(10))
76
- concat_portfolio = pd.concat([concat_portfolio, removed_lineups, team_lineups])
 
 
77
 
78
  return concat_portfolio.head(lineup_target)
 
51
  )
52
 
53
  removed_df = working_df[remove_mask]
 
54
  locked_df = working_df[lock_mask]
 
55
 
56
  removed_lineups = small_field_preset(removed_df, math.ceil(lineup_target / (list_size * 3)), excluded_cols)
57
  print(len(removed_lineups))
58
+ # Check if locked_df is empty before calling large_field_preset
59
+ if not locked_df.empty:
60
+ locked_lineups = large_field_preset(locked_df, math.ceil(lineup_target / (list_size * 3)), excluded_cols)
61
+ print(len(locked_lineups))
62
+ concat_portfolio = pd.concat([concat_portfolio, removed_lineups, locked_lineups])
63
+ else:
64
+ # If no lineups contain this player, just add the removed lineups
65
+ print(f"No lineups found containing {player}")
66
+ concat_portfolio = pd.concat([concat_portfolio, removed_lineups])
67
 
68
  for team in top_owned_teams:
69
  working_df = portfolio.copy()
 
71
  teams_df = working_df[working_df['Stack'] == team]
72
 
73
  removed_lineups = small_field_preset(removed_df, math.ceil(lineup_target / (list_size * 3)), excluded_cols)
74
+ # Check if teams_df is empty before calling large_field_preset
75
+ if not teams_df.empty:
76
+ team_lineups = large_field_preset(teams_df, math.ceil(lineup_target / (list_size * 3)), excluded_cols)
77
+ concat_portfolio = pd.concat([concat_portfolio, removed_lineups, team_lineups])
78
+ else:
79
+ # If no lineups have this team stacked, just add the removed lineups
80
+ print(f"No lineups found with {team} stacked")
81
+ concat_portfolio = pd.concat([concat_portfolio, removed_lineups])
82
 
83
  return concat_portfolio.head(lineup_target)