From a31fd15a8c314680b63d5c4f04eee8952c93c52b Mon Sep 17 00:00:00 2001 From: Sourcery AI Date: Wed, 17 Feb 2021 10:02:15 +0000 Subject: [PATCH] 'Refactored by Sourcery' --- pybaseball/amateur_draft.py | 5 +- pybaseball/batting_leaders.py | 3 +- pybaseball/lahman.py | 236 +++++++++++++++------------- pybaseball/league_batting_stats.py | 9 +- pybaseball/league_pitching_stats.py | 9 +- pybaseball/pitching_leaders.py | 3 +- pybaseball/playerid_lookup.py | 4 +- pybaseball/plotting.py | 4 +- pybaseball/retrosheet.py | 4 +- pybaseball/standings.py | 23 +-- pybaseball/statcast.py | 4 +- pybaseball/statcast_batter.py | 6 +- pybaseball/statcast_pitcher.py | 3 +- pybaseball/team_batting.py | 3 - pybaseball/team_game_logs.py | 3 +- pybaseball/top_prospects.py | 10 +- 16 files changed, 169 insertions(+), 160 deletions(-) diff --git a/pybaseball/amateur_draft.py b/pybaseball/amateur_draft.py index d49c1aa..0ef9d68 100644 --- a/pybaseball/amateur_draft.py +++ b/pybaseball/amateur_draft.py @@ -3,9 +3,8 @@ def get_draft_results(year, round): url = f"https://www.baseball-reference.com/draft/?year_ID={year}&draft_round={round}&draft_type=junreg&query_type=year_round&" - res = requests.get(url, timeout=None).content - draft_results = pd.read_html(res) - return draft_results + res = requests.get(url, timeout=None).content + return pd.read_html(res) def amateur_draft(year, round, keep_stats=True): draft_results = get_draft_results(year, round) diff --git a/pybaseball/batting_leaders.py b/pybaseball/batting_leaders.py index 34f777c..9cc5b7e 100644 --- a/pybaseball/batting_leaders.py +++ b/pybaseball/batting_leaders.py @@ -61,6 +61,5 @@ def batting_stats(start_season, end_season=None, league='all', qual=1, ind=1): if end_season is None: end_season = start_season soup = get_soup(start_season=start_season, end_season=end_season, league=league, qual=qual, ind=ind) - table = get_table(soup, ind) - return table + return get_table(soup, ind) diff --git a/pybaseball/lahman.py b/pybaseball/lahman.py index f835f08..e74d9d4 100644 --- a/pybaseball/lahman.py +++ b/pybaseball/lahman.py @@ -31,141 +31,163 @@ def download_lahman(): # instead of the session ZipFile object def parks(): - # do this for every table in the lahman db so they can exist as separate functions - z = get_lahman_zip() - f = os.path.join(base_string, "Parks.csv") - data = pd.read_csv(f if z is None else z.open(f), header=0, sep=',', quotechar="'") - return data + # do this for every table in the lahman db so they can exist as separate functions + z = get_lahman_zip() + f = os.path.join(base_string, "Parks.csv") + return pd.read_csv( + f if z is None else z.open(f), header=0, sep=',', quotechar="'" + ) def all_star_full(): - z = get_lahman_zip() - f = os.path.join(base_string, "AllstarFull.csv") - data = pd.read_csv(f if z is None else z.open(f), header=0, sep=',', quotechar="'") - return data + z = get_lahman_zip() + f = os.path.join(base_string, "AllstarFull.csv") + return pd.read_csv( + f if z is None else z.open(f), header=0, sep=',', quotechar="'" + ) def appearances(): - z = get_lahman_zip() - f = os.path.join(base_string, "Appearances.csv") - data = pd.read_csv(f if z is None else z.open(f), header=0, sep=',', quotechar="'") - return data + z = get_lahman_zip() + f = os.path.join(base_string, "Appearances.csv") + return pd.read_csv( + f if z is None else z.open(f), header=0, sep=',', quotechar="'" + ) def awards_managers(): - z = get_lahman_zip() - f = os.path.join(base_string, "AwardsManagers.csv") - data = pd.read_csv(f if z is None else z.open(f), header=0, sep=',', quotechar="'") - return data + z = get_lahman_zip() + f = os.path.join(base_string, "AwardsManagers.csv") + return pd.read_csv( + f if z is None else z.open(f), header=0, sep=',', quotechar="'" + ) def awards_players(): - z = get_lahman_zip() - f = os.path.join(base_string, "AwardsPlayers.csv") - data = pd.read_csv(f if z is None else z.open(f), header=0, sep=',', quotechar="'") - return data + z = get_lahman_zip() + f = os.path.join(base_string, "AwardsPlayers.csv") + return pd.read_csv( + f if z is None else z.open(f), header=0, sep=',', quotechar="'" + ) def awards_share_managers(): - z = get_lahman_zip() - f = os.path.join(base_string, "AwardsShareManagers.csv") - data = pd.read_csv(f if z is None else z.open(f), header=0, sep=',', quotechar="'") - return data + z = get_lahman_zip() + f = os.path.join(base_string, "AwardsShareManagers.csv") + return pd.read_csv( + f if z is None else z.open(f), header=0, sep=',', quotechar="'" + ) def awards_share_players(): - z = get_lahman_zip() - f = os.path.join(base_string, "AwardsSharePlayers.csv") - data = pd.read_csv(f if z is None else z.open(f), header=0, sep=',', quotechar="'") - return data + z = get_lahman_zip() + f = os.path.join(base_string, "AwardsSharePlayers.csv") + return pd.read_csv( + f if z is None else z.open(f), header=0, sep=',', quotechar="'" + ) def batting(): - z = get_lahman_zip() - f = os.path.join(base_string, "Batting.csv") - data = pd.read_csv(f if z is None else z.open(f), header=0, sep=',', quotechar="'") - return data + z = get_lahman_zip() + f = os.path.join(base_string, "Batting.csv") + return pd.read_csv( + f if z is None else z.open(f), header=0, sep=',', quotechar="'" + ) def batting_post(): - z = get_lahman_zip() - f = os.path.join(base_string, "BattingPost.csv") - data = pd.read_csv(f if z is None else z.open(f), header=0, sep=',', quotechar="'") - return data + z = get_lahman_zip() + f = os.path.join(base_string, "BattingPost.csv") + return pd.read_csv( + f if z is None else z.open(f), header=0, sep=',', quotechar="'" + ) def college_playing(): - z = get_lahman_zip() - f = os.path.join(base_string, "CollegePlaying.csv") - data = pd.read_csv(f if z is None else z.open(f), header=0, sep=',', quotechar="'") - return data + z = get_lahman_zip() + f = os.path.join(base_string, "CollegePlaying.csv") + return pd.read_csv( + f if z is None else z.open(f), header=0, sep=',', quotechar="'" + ) def fielding(): - z = get_lahman_zip() - f = os.path.join(base_string, "Fielding.csv") - data = pd.read_csv(f if z is None else z.open(f), header=0, sep=',', quotechar="'") - return data + z = get_lahman_zip() + f = os.path.join(base_string, "Fielding.csv") + return pd.read_csv( + f if z is None else z.open(f), header=0, sep=',', quotechar="'" + ) def fielding_of(): - z = get_lahman_zip() - f = os.path.join(base_string, "FieldingOF.csv") - data = pd.read_csv(f if z is None else z.open(f), header=0, sep=',', quotechar="'") - return data + z = get_lahman_zip() + f = os.path.join(base_string, "FieldingOF.csv") + return pd.read_csv( + f if z is None else z.open(f), header=0, sep=',', quotechar="'" + ) def fielding_of_split(): - z = get_lahman_zip() - f = os.path.join(base_string, "FieldingOFsplit.csv") - data = pd.read_csv(f if z is None else z.open(f), header=0, sep=',', quotechar="'") - return data + z = get_lahman_zip() + f = os.path.join(base_string, "FieldingOFsplit.csv") + return pd.read_csv( + f if z is None else z.open(f), header=0, sep=',', quotechar="'" + ) def fielding_post(): - z = get_lahman_zip() - f = os.path.join(base_string, "FieldingPost.csv") - data = pd.read_csv(f if z is None else z.open(f), header=0, sep=',', quotechar="'") - return data + z = get_lahman_zip() + f = os.path.join(base_string, "FieldingPost.csv") + return pd.read_csv( + f if z is None else z.open(f), header=0, sep=',', quotechar="'" + ) def hall_of_fame(): - z = get_lahman_zip() - f = os.path.join(base_string, "HallOfFame.csv") - data = pd.read_csv(f if z is None else z.open(f), header=0, sep=',', quotechar="'") - return data + z = get_lahman_zip() + f = os.path.join(base_string, "HallOfFame.csv") + return pd.read_csv( + f if z is None else z.open(f), header=0, sep=',', quotechar="'" + ) def home_games(): - z = get_lahman_zip() - f = os.path.join(base_string, "HomeGames.csv") - data = pd.read_csv(f if z is None else z.open(f), header=0, sep=',', quotechar="'") - return data + z = get_lahman_zip() + f = os.path.join(base_string, "HomeGames.csv") + return pd.read_csv( + f if z is None else z.open(f), header=0, sep=',', quotechar="'" + ) def managers(): - z = get_lahman_zip() - f = os.path.join(base_string, "Managers.csv") - data = pd.read_csv(f if z is None else z.open(f), header=0, sep=',', quotechar="'") - return data + z = get_lahman_zip() + f = os.path.join(base_string, "Managers.csv") + return pd.read_csv( + f if z is None else z.open(f), header=0, sep=',', quotechar="'" + ) def managers_half(): - z = get_lahman_zip() - f = os.path.join(base_string, "ManagersHalf.csv") - data = pd.read_csv(f if z is None else z.open(f), header=0, sep=',', quotechar="'") - return data + z = get_lahman_zip() + f = os.path.join(base_string, "ManagersHalf.csv") + return pd.read_csv( + f if z is None else z.open(f), header=0, sep=',', quotechar="'" + ) # Alias for people -- the new name for master def master(): return people() def people(): - z = get_lahman_zip() - f = os.path.join(base_string, "People.csv") - data = pd.read_csv(f if z is None else z.open(f), header=0, sep=',', quotechar="'") - return data + z = get_lahman_zip() + f = os.path.join(base_string, "People.csv") + return pd.read_csv( + f if z is None else z.open(f), header=0, sep=',', quotechar="'" + ) def pitching(): - z = get_lahman_zip() - f = os.path.join(base_string, "Pitching.csv") - data = pd.read_csv(f if z is None else z.open(f), header=0, sep=',', quotechar="'") - return data + z = get_lahman_zip() + f = os.path.join(base_string, "Pitching.csv") + return pd.read_csv( + f if z is None else z.open(f), header=0, sep=',', quotechar="'" + ) def pitching_post(): - z = get_lahman_zip() - f = os.path.join(base_string, "PitchingPost.csv") - data = pd.read_csv(f if z is None else z.open(f), header=0, sep=',', quotechar="'") - return data + z = get_lahman_zip() + f = os.path.join(base_string, "PitchingPost.csv") + return pd.read_csv( + f if z is None else z.open(f), header=0, sep=',', quotechar="'" + ) def salaries(): - z = get_lahman_zip() - f = os.path.join(base_string, "Salaries.csv") - data = pd.read_csv(f if z is None else z.open(f), header=0, sep=',', quotechar="'") - return data + z = get_lahman_zip() + f = os.path.join(base_string, "Salaries.csv") + return pd.read_csv( + f if z is None else z.open(f), header=0, sep=',', quotechar="'" + ) def schools(): z = get_lahman_zip() @@ -174,26 +196,30 @@ def schools(): return data def series_post(): - z = get_lahman_zip() - f = os.path.join(base_string, "SeriesPost.csv") - data = pd.read_csv(f if z is None else z.open(f), header=0, sep=',', quotechar="'") - return data + z = get_lahman_zip() + f = os.path.join(base_string, "SeriesPost.csv") + return pd.read_csv( + f if z is None else z.open(f), header=0, sep=',', quotechar="'" + ) def teams(): - z = get_lahman_zip() - f = os.path.join(base_string, "Teams.csv") - data = pd.read_csv(f if z is None else z.open(f), header=0, sep=',', quotechar="'") - return data + z = get_lahman_zip() + f = os.path.join(base_string, "Teams.csv") + return pd.read_csv( + f if z is None else z.open(f), header=0, sep=',', quotechar="'" + ) def teams_franchises(): - z = get_lahman_zip() - f = os.path.join(base_string, "TeamsFranchises.csv") - data = pd.read_csv(f if z is None else z.open(f), header=0, sep=',', quotechar="'") - return data + z = get_lahman_zip() + f = os.path.join(base_string, "TeamsFranchises.csv") + return pd.read_csv( + f if z is None else z.open(f), header=0, sep=',', quotechar="'" + ) def teams_half(): - z = get_lahman_zip() - f = os.path.join(base_string, "TeamsHalf.csv") - data = pd.read_csv(f if z is None else z.open(f), header=0, sep=',', quotechar="'") - return data + z = get_lahman_zip() + f = os.path.join(base_string, "TeamsHalf.csv") + return pd.read_csv( + f if z is None else z.open(f), header=0, sep=',', quotechar="'" + ) diff --git a/pybaseball/league_batting_stats.py b/pybaseball/league_batting_stats.py index fa6eaa7..86ad084 100644 --- a/pybaseball/league_batting_stats.py +++ b/pybaseball/league_batting_stats.py @@ -115,8 +115,7 @@ def bwar_bat(return_all=False): c=pd.read_csv(io.StringIO(s.decode('utf-8'))) if return_all: return c - else: - cols_to_keep = ['name_common', 'mlb_ID', 'player_ID', 'year_ID', 'team_ID', 'stint_ID', 'lg_ID', - 'pitcher','G', 'PA', 'salary', 'runs_above_avg', 'runs_above_avg_off','runs_above_avg_def', - 'WAR_rep','WAA','WAR'] - return c[cols_to_keep] \ No newline at end of file + cols_to_keep = ['name_common', 'mlb_ID', 'player_ID', 'year_ID', 'team_ID', 'stint_ID', 'lg_ID', + 'pitcher','G', 'PA', 'salary', 'runs_above_avg', 'runs_above_avg_off','runs_above_avg_def', + 'WAR_rep','WAA','WAR'] + return c[cols_to_keep] \ No newline at end of file diff --git a/pybaseball/league_pitching_stats.py b/pybaseball/league_pitching_stats.py index 3542402..c94d0ba 100644 --- a/pybaseball/league_pitching_stats.py +++ b/pybaseball/league_pitching_stats.py @@ -118,8 +118,7 @@ def bwar_pitch(return_all=False): c=pd.read_csv(io.StringIO(s.decode('utf-8'))) if return_all: return c - else: - cols_to_keep = ['name_common', 'mlb_ID', 'player_ID', 'year_ID', 'team_ID', 'stint_ID', 'lg_ID', - 'G', 'GS', 'RA','xRA', 'BIP', 'BIP_perc','salary', 'ERA_plus', 'WAR_rep', 'WAA', - 'WAA_adj','WAR'] - return c[cols_to_keep] + cols_to_keep = ['name_common', 'mlb_ID', 'player_ID', 'year_ID', 'team_ID', 'stint_ID', 'lg_ID', + 'G', 'GS', 'RA','xRA', 'BIP', 'BIP_perc','salary', 'ERA_plus', 'WAR_rep', 'WAA', + 'WAA_adj','WAR'] + return c[cols_to_keep] diff --git a/pybaseball/pitching_leaders.py b/pybaseball/pitching_leaders.py index 609c917..cea6a2a 100644 --- a/pybaseball/pitching_leaders.py +++ b/pybaseball/pitching_leaders.py @@ -77,5 +77,4 @@ def pitching_stats(start_season, end_season=None, league='all', qual=1, ind=1): if end_season is None: end_season = start_season soup = get_soup(start_season=start_season, end_season=end_season, league=league, qual=qual, ind=ind) - table = get_table(soup, ind) - return table + return get_table(soup, ind) diff --git a/pybaseball/playerid_lookup.py b/pybaseball/playerid_lookup.py index 780b8d2..593dc05 100644 --- a/pybaseball/playerid_lookup.py +++ b/pybaseball/playerid_lookup.py @@ -57,8 +57,7 @@ def playerid_lookup(last=None, first=None, player_list=None): # if player_list has a value, then the user is passing in a list of players # the list of players may be comma delimited for last, first, or just last if player_list: - player_counter = 1 - for player in player_list: + for player_counter, player in enumerate(player_list, start=1): last = player.split(",")[0].strip() first = None if (len(player.split(",")) > 1): @@ -67,7 +66,6 @@ def playerid_lookup(last=None, first=None, player_list=None): results = playerid_lookup(last, first) else: results = results.append(playerid_lookup(last, first), ignore_index=True) - player_counter += 1 return results if first is None: diff --git a/pybaseball/plotting.py b/pybaseball/plotting.py index da67de9..ebd45e6 100644 --- a/pybaseball/plotting.py +++ b/pybaseball/plotting.py @@ -25,7 +25,7 @@ def plot_stadium(team): title = {'text': [name], 'subtitle': [location]} if team == 'generic': title = 'Generic Stadium' - stadium = alt.Chart(coords, title=title).mark_line().encode( + return alt.Chart(coords, title=title).mark_line().encode( x=alt.X('x', axis=None, scale=alt.Scale(zero=True)), y=alt.Y('y', axis=None, scale=alt.Scale(zero=True)), color=alt.Color( @@ -34,8 +34,6 @@ def plot_stadium(team): order='segment' ) - return stadium - def spraychart(data, team_stadium, title='', tooltips=[], size=100, colorby='events', legend_title='', width=500, height=500): diff --git a/pybaseball/retrosheet.py b/pybaseball/retrosheet.py index e16a1b9..0055020 100644 --- a/pybaseball/retrosheet.py +++ b/pybaseball/retrosheet.py @@ -133,7 +133,7 @@ def events(season, type='regular', export_dir='.'): subsubtree = t event_files = [t.path for t in repo.get_git_tree(subsubtree.sha).tree if str(season) in t.path] - if len(event_files) == 0: + if not event_files: raise ValueError(f'Event files not available for {season}') except RateLimitExceededException: warnings.warn( @@ -162,7 +162,7 @@ def rosters(season): subtree = t rosters = [t.path for t in repo.get_git_tree(subtree.sha).tree if str(season) in t.path] - if len(rosters) == 0: + if not rosters: raise ValueError(f'Rosters not available for {season}') except RateLimitExceededException: warnings.warn( diff --git a/pybaseball/standings.py b/pybaseball/standings.py index 8a57ce9..c52e005 100644 --- a/pybaseball/standings.py +++ b/pybaseball/standings.py @@ -11,7 +11,7 @@ def get_soup(year): def get_tables(soup, season): datasets = [] - if(season>=1969): + if (season>=1969): tables = soup.find_all('table') for table in tables: data = [] @@ -30,24 +30,24 @@ def get_tables(soup, season): table = soup.find('table') headings = [th.get_text() for th in table.find("tr").find_all("th")] headings[0] = "Name" - if(season>=1930): + if (season>=1930): for i in range(15): headings.pop() - elif(season>=1876): - for i in range(14): headings.pop() + elif season>=1876: + for _ in range(14): headings.pop() else: - for i in range(16): headings.pop() + for _ in range(16): headings.pop() data.append(headings) table_body = table.find('tbody') rows = table_body.find_all('tr') for row in rows: if row.find_all('a') == []: continue cols = row.find_all('td') - if(season>=1930): - for i in range(15): cols.pop() - elif(season>=1876): - for i in range(14): cols.pop() + if (season>=1930): + for _ in range(15): cols.pop() + elif season>=1876: + for _ in range(14): cols.pop() else: - for i in range(16): cols.pop() + for _ in range(16): cols.pop() cols = [ele.text.strip() for ele in cols] cols.insert(0,row.find_all('a')[0]['title']) # team name data.append([ele for ele in cols if ele]) @@ -72,7 +72,8 @@ def standings(season=None): # list of seasons whose table placement breaks the site's usual pattern exceptions = [1884, 1885, 1886, 1887, 1888, 1889, 1890, 1892, 1903] if (season>1904 or season in exceptions): code = BeautifulSoup(t[16], "lxml") - elif season<=1904: code = BeautifulSoup(t[15], "lxml") + else: + code = BeautifulSoup(t[15], "lxml") tables = get_tables(code, season) tables = [pd.DataFrame(table) for table in tables] for idx in range(len(tables)): diff --git a/pybaseball/statcast.py b/pybaseball/statcast.py index 028e3db..6194de4 100644 --- a/pybaseball/statcast.py +++ b/pybaseball/statcast.py @@ -184,8 +184,6 @@ def statcast(start_dt=None, end_dt=None, team=None, verbose=True): start_dt, end_dt = sanitize_input(start_dt, end_dt) - # 3 days or less -> a quick one-shot request. Greater than 3 days -> break it into multiple smaller queries - small_query_threshold = 5 # inputs are valid if either both or zero dates are supplied. Not valid of only one given. @@ -195,6 +193,8 @@ def statcast(start_dt=None, end_dt=None, team=None, verbose=True): d1 = datetime.datetime.strptime(start_dt, date_format) d2 = datetime.datetime.strptime(end_dt, date_format) days_in_query = (d2 - d1).days + # 3 days or less -> a quick one-shot request. Greater than 3 days -> break it into multiple smaller queries + small_query_threshold = 5 if days_in_query <= small_query_threshold: data = small_request(start_dt,end_dt) else: diff --git a/pybaseball/statcast_batter.py b/pybaseball/statcast_batter.py index 56a5fd7..faf4dfb 100644 --- a/pybaseball/statcast_batter.py +++ b/pybaseball/statcast_batter.py @@ -16,11 +16,9 @@ def statcast_batter(start_dt=None, end_dt=None, player_id=None): # inputs are valid if either both or zero dates are supplied. Not valid of only one given. if start_dt and end_dt: url = 'https://baseballsavant.mlb.com/statcast_search/csv?all=true&hfPT=&hfAB=&hfBBT=&hfPR=&hfZ=&stadium=&hfBBL=&hfNewZones=&hfGT=R%7CPO%7CS%7C=&hfSea=&hfSit=&player_type=batter&hfOuts=&opponent=&pitcher_throws=&batter_stands=&hfSA=&game_date_gt={}&game_date_lt={}&batters_lookup%5B%5D={}&team=&position=&hfRO=&home_road=&hfFlag=&metric_1=&hfInn=&min_pitches=0&min_results=0&group_by=name&sort_col=pitches&player_event_sort=h_launch_speed&sort_order=desc&min_abs=0&type=details&' - df = split_request(start_dt, end_dt, player_id, url) - return df + return split_request(start_dt, end_dt, player_id, url) def statcast_batter_exitvelo_barrels(year, minBBE="q"): url = f"https://baseballsavant.mlb.com/leaderboard/statcast?type=batter&year={year}&position=&team=&min={minBBE}&csv=true" res = requests.get(url, timeout=None).content - data = pd.read_csv(io.StringIO(res.decode('utf-8'))) - return data + return pd.read_csv(io.StringIO(res.decode('utf-8'))) diff --git a/pybaseball/statcast_pitcher.py b/pybaseball/statcast_pitcher.py index 2dea057..113a75b 100644 --- a/pybaseball/statcast_pitcher.py +++ b/pybaseball/statcast_pitcher.py @@ -15,5 +15,4 @@ def statcast_pitcher(start_dt=None, end_dt=None, player_id=None): # inputs are valid if either both or zero dates are supplied. Not valid of only one given. if start_dt and end_dt: url = 'https://baseballsavant.mlb.com/statcast_search/csv?all=true&hfPT=&hfAB=&hfBBT=&hfPR=&hfZ=&stadium=&hfBBL=&hfNewZones=&hfGT=R%7CPO%7CS%7C=&hfSea=&hfSit=&player_type=pitcher&hfOuts=&opponent=&pitcher_throws=&batter_stands=&hfSA=&game_date_gt={}&game_date_lt={}&pitchers_lookup%5B%5D={}&team=&position=&hfRO=&home_road=&hfFlag=&metric_1=&hfInn=&min_pitches=0&min_results=0&group_by=name&sort_col=pitches&player_event_sort=h_launch_speed&sort_order=desc&min_abs=0&type=details&' - df = split_request(start_dt, end_dt, player_id, url) - return df + return split_request(start_dt, end_dt, player_id, url) diff --git a/pybaseball/team_batting.py b/pybaseball/team_batting.py index 460356a..d53853e 100644 --- a/pybaseball/team_batting.py +++ b/pybaseball/team_batting.py @@ -45,9 +45,6 @@ def postprocessing(data): data[col] = data[col].str.strip(' %') data[col] = data[col].str.strip('%') data[col] = data[col].astype(float)/100. - else: - pass - # convert columns to numeric not_numeric = ['Team'] numeric_cols = [col for col in data.columns if col not in not_numeric] diff --git a/pybaseball/team_game_logs.py b/pybaseball/team_game_logs.py index 8e09dae..89a2768 100644 --- a/pybaseball/team_game_logs.py +++ b/pybaseball/team_game_logs.py @@ -14,8 +14,7 @@ def get_table(season, team, log_type): table = soup.find("table", attrs=dict(id=table_id)) if table is None: raise RuntimeError("Table with expected id not found on scraped page.") - data = pd.read_html(str(table))[0] - return data + return pd.read_html(str(table))[0] def postprocess(data): diff --git a/pybaseball/top_prospects.py b/pybaseball/top_prospects.py index 6f88541..a9619b6 100644 --- a/pybaseball/top_prospects.py +++ b/pybaseball/top_prospects.py @@ -2,17 +2,15 @@ import requests def top_prospects(teamName=None, playerType=None): - teamUrl = "" if teamName == None else teamName.lower() + '/' + teamUrl = "" if teamName is None else teamName.lower() + '/' url = f"https://www.mlb.com/{teamUrl}prospects/stats/top-prospects" res = requests.get(url, timeout=None).content prospectList = pd.read_html(res) if playerType == "batters": - topBattingProspects = postprocess(prospectList[0]) - return topBattingProspects + return postprocess(prospectList[0]) elif playerType == "pitchers": - topPitchingProspects = postprocess(prospectList[1]) - return topPitchingProspects - elif playerType == None: + return postprocess(prospectList[1]) + elif playerType is None: topProspects = pd.concat(prospectList) topProspects.sort_values(by=['Rk'], inplace = True) topProspects = postprocess(topProspects)