James McCool commited on
Commit
db0a705
·
1 Parent(s): f135d43

Add robust numeric type conversion for prop calculations to prevent data errors

Browse files

Modify prop calculation logic in multiple tabs to use pd.to_numeric() with 'coerce' parameter, ensuring safe numeric conversion and preventing potential runtime errors when processing player prop data

Files changed (1) hide show
  1. app.py +26 -26
app.py CHANGED
@@ -366,25 +366,25 @@ with tab5:
366
  player_var = player_var.reset_index()
367
 
368
  if prop_type_var == 'points':
369
- df['Median'] = df['Points']
370
  elif prop_type_var == 'threes':
371
- df['Median'] = df['3P']
372
  elif prop_type_var == 'rebounds':
373
- df['Median'] = df['Rebounds']
374
  elif prop_type_var == 'assists':
375
- df['Median'] = df['Assists']
376
  elif prop_type_var == 'blocks':
377
- df['Median'] = df['Blocks']
378
  elif prop_type_var == 'steals':
379
- df['Median'] = df['Steals']
380
  elif prop_type_var == 'PRA':
381
- df['Median'] = df['Points'] + df['Rebounds'] + df['Assists']
382
  elif prop_type_var == 'points+rebounds':
383
- df['Median'] = df['Points'] + df['Rebounds']
384
  elif prop_type_var == 'points+assists':
385
- df['Median'] = df['Points'] + df['Assists']
386
  elif prop_type_var == 'rebounds+assists':
387
- df['Median'] = df['Assists'] + df['Rebounds']
388
 
389
  flex_file = df
390
  flex_file['Floor'] = (flex_file['Median'] * .25) + (flex_file['Minutes'] * .25)
@@ -544,21 +544,21 @@ with tab6:
544
  df.replace("", 0, inplace=True)
545
 
546
  if prop == "NBA_GAME_PLAYER_POINTS" or prop == "Points":
547
- df['Median'] = df['Points']
548
  elif prop == "NBA_GAME_PLAYER_REBOUNDS" or prop == "Rebounds":
549
- df['Median'] = df['Rebounds']
550
  elif prop == "NBA_GAME_PLAYER_ASSISTS" or prop == "Assists":
551
- df['Median'] = df['Assists']
552
  elif prop == "NBA_GAME_PLAYER_3_POINTERS_MADE" or prop == "3-Pointers Made":
553
- df['Median'] = df['3P']
554
  elif prop == "NBA_GAME_PLAYER_POINTS_REBOUNDS_ASSISTS" or prop == "Points + Assists + Rebounds":
555
- df['Median'] = df['Points'] + df['Rebounds'] + df['Assists']
556
  elif prop == "NBA_GAME_PLAYER_POINTS_REBOUNDS" or prop == "Points + Rebounds":
557
- df['Median'] = df['Points'] + df['Rebounds']
558
  elif prop == "NBA_GAME_PLAYER_POINTS_ASSISTS" or prop == "Points + Assists":
559
- df['Median'] = df['Points'] + df['Assists']
560
  elif prop == "NBA_GAME_PLAYER_REBOUNDS_ASSISTS" or prop == "Assists + Rebounds":
561
- df['Median'] = df['Rebounds'] + df['Assists']
562
 
563
  flex_file = df.copy()
564
  flex_file['Floor'] = flex_file['Median'] * .25
@@ -698,21 +698,21 @@ with tab6:
698
  df.replace("", 0, inplace=True)
699
 
700
  if prop_type_var == "NBA_GAME_PLAYER_POINTS" or prop_type_var == "Points":
701
- df['Median'] = df['Points']
702
  elif prop_type_var == "NBA_GAME_PLAYER_REBOUNDS" or prop_type_var == "Rebounds":
703
- df['Median'] = df['Rebounds']
704
  elif prop_type_var == "NBA_GAME_PLAYER_ASSISTS" or prop_type_var == "Assists":
705
- df['Median'] = df['Assists']
706
  elif prop_type_var == "NBA_GAME_PLAYER_3_POINTERS_MADE" or prop_type_var == "3-Pointers Made":
707
- df['Median'] = df['3P']
708
  elif prop_type_var == "NBA_GAME_PLAYER_POINTS_REBOUNDS_ASSISTS" or prop_type_var == "Points + Assists + Rebounds":
709
- df['Median'] = df['Points'] + df['Rebounds'] + df['Assists']
710
  elif prop_type_var == "NBA_GAME_PLAYER_POINTS_REBOUNDS" or prop_type_var == "Points + Rebounds":
711
- df['Median'] = df['Points'] + df['Rebounds']
712
  elif prop_type_var == "NBA_GAME_PLAYER_POINTS_ASSISTS" or prop_type_var == "Points + Assists":
713
- df['Median'] = df['Points'] + df['Assists']
714
  elif prop_type_var == "NBA_GAME_PLAYER_REBOUNDS_ASSISTS" or prop_type_var == "Assists + Rebounds":
715
- df['Median'] = df['Rebounds'] + df['Assists']
716
 
717
  flex_file = df.copy()
718
  flex_file['Floor'] = flex_file['Median'] * .25
 
366
  player_var = player_var.reset_index()
367
 
368
  if prop_type_var == 'points':
369
+ df['Median'] = pd.to_numeric(df['Points'], errors='coerce')
370
  elif prop_type_var == 'threes':
371
+ df['Median'] = pd.to_numeric(df['3P'], errors='coerce')
372
  elif prop_type_var == 'rebounds':
373
+ df['Median'] = pd.to_numeric(df['Rebounds'], errors='coerce')
374
  elif prop_type_var == 'assists':
375
+ df['Median'] = pd.to_numeric(df['Assists'], errors='coerce')
376
  elif prop_type_var == 'blocks':
377
+ df['Median'] = pd.to_numeric(df['Blocks'], errors='coerce')
378
  elif prop_type_var == 'steals':
379
+ df['Median'] = pd.to_numeric(df['Steals'], errors='coerce')
380
  elif prop_type_var == 'PRA':
381
+ df['Median'] = pd.to_numeric(df['Points'], errors='coerce') + pd.to_numeric(df['Rebounds'], errors='coerce') + pd.to_numeric(df['Assists'], errors='coerce')
382
  elif prop_type_var == 'points+rebounds':
383
+ df['Median'] = pd.to_numeric(df['Points'], errors='coerce') + pd.to_numeric(df['Rebounds'], errors='coerce')
384
  elif prop_type_var == 'points+assists':
385
+ df['Median'] = pd.to_numeric(df['Points'], errors='coerce') + pd.to_numeric(df['Assists'], errors='coerce')
386
  elif prop_type_var == 'rebounds+assists':
387
+ df['Median'] = pd.to_numeric(df['Assists'], errors='coerce') + pd.to_numeric(df['Rebounds'], errors='coerce')
388
 
389
  flex_file = df
390
  flex_file['Floor'] = (flex_file['Median'] * .25) + (flex_file['Minutes'] * .25)
 
544
  df.replace("", 0, inplace=True)
545
 
546
  if prop == "NBA_GAME_PLAYER_POINTS" or prop == "Points":
547
+ df['Median'] = pd.to_numeric(df['Points'], errors='coerce')
548
  elif prop == "NBA_GAME_PLAYER_REBOUNDS" or prop == "Rebounds":
549
+ df['Median'] = pd.to_numeric(df['Rebounds'], errors='coerce')
550
  elif prop == "NBA_GAME_PLAYER_ASSISTS" or prop == "Assists":
551
+ df['Median'] = pd.to_numeric(df['Assists'], errors='coerce')
552
  elif prop == "NBA_GAME_PLAYER_3_POINTERS_MADE" or prop == "3-Pointers Made":
553
+ df['Median'] = pd.to_numeric(df['3P'], errors='coerce')
554
  elif prop == "NBA_GAME_PLAYER_POINTS_REBOUNDS_ASSISTS" or prop == "Points + Assists + Rebounds":
555
+ df['Median'] = pd.to_numeric(df['Points'], errors='coerce') + pd.to_numeric(df['Rebounds'], errors='coerce') + pd.to_numeric(df['Assists'], errors='coerce')
556
  elif prop == "NBA_GAME_PLAYER_POINTS_REBOUNDS" or prop == "Points + Rebounds":
557
+ df['Median'] = pd.to_numeric(df['Points'], errors='coerce') + pd.to_numeric(df['Rebounds'], errors='coerce')
558
  elif prop == "NBA_GAME_PLAYER_POINTS_ASSISTS" or prop == "Points + Assists":
559
+ df['Median'] = pd.to_numeric(df['Points'], errors='coerce') + pd.to_numeric(df['Assists'], errors='coerce')
560
  elif prop == "NBA_GAME_PLAYER_REBOUNDS_ASSISTS" or prop == "Assists + Rebounds":
561
+ df['Median'] = pd.to_numeric(df['Rebounds'], errors='coerce') + pd.to_numeric(df['Assists'], errors='coerce')
562
 
563
  flex_file = df.copy()
564
  flex_file['Floor'] = flex_file['Median'] * .25
 
698
  df.replace("", 0, inplace=True)
699
 
700
  if prop_type_var == "NBA_GAME_PLAYER_POINTS" or prop_type_var == "Points":
701
+ df['Median'] = pd.to_numeric(df['Points'], errors='coerce')
702
  elif prop_type_var == "NBA_GAME_PLAYER_REBOUNDS" or prop_type_var == "Rebounds":
703
+ df['Median'] = pd.to_numeric(df['Rebounds'], errors='coerce')
704
  elif prop_type_var == "NBA_GAME_PLAYER_ASSISTS" or prop_type_var == "Assists":
705
+ df['Median'] = pd.to_numeric(df['Assists'], errors='coerce')
706
  elif prop_type_var == "NBA_GAME_PLAYER_3_POINTERS_MADE" or prop_type_var == "3-Pointers Made":
707
+ df['Median'] = pd.to_numeric(df['3P'], errors='coerce')
708
  elif prop_type_var == "NBA_GAME_PLAYER_POINTS_REBOUNDS_ASSISTS" or prop_type_var == "Points + Assists + Rebounds":
709
+ df['Median'] = pd.to_numeric(df['Points'], errors='coerce') + pd.to_numeric(df['Rebounds'], errors='coerce') + pd.to_numeric(df['Assists'], errors='coerce')
710
  elif prop_type_var == "NBA_GAME_PLAYER_POINTS_REBOUNDS" or prop_type_var == "Points + Rebounds":
711
+ df['Median'] = pd.to_numeric(df['Points'], errors='coerce') + pd.to_numeric(df['Rebounds'], errors='coerce')
712
  elif prop_type_var == "NBA_GAME_PLAYER_POINTS_ASSISTS" or prop_type_var == "Points + Assists":
713
+ df['Median'] = pd.to_numeric(df['Points'], errors='coerce') + pd.to_numeric(df['Assists'], errors='coerce')
714
  elif prop_type_var == "NBA_GAME_PLAYER_REBOUNDS_ASSISTS" or prop_type_var == "Assists + Rebounds":
715
+ df['Median'] = pd.to_numeric(df['Rebounds'], errors='coerce') + pd.to_numeric(df['Assists'], errors='coerce')
716
 
717
  flex_file = df.copy()
718
  flex_file['Floor'] = flex_file['Median'] * .25