Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery Starbot ⭐ refactored schorrm/pybaseball #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions pybaseball/amateur_draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment on lines -6 to +7
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_draft_results refactored with the following changes:


def amateur_draft(year, round, keep_stats=True):
draft_results = get_draft_results(year, round)
Expand Down
3 changes: 1 addition & 2 deletions pybaseball/batting_leaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function batting_stats refactored with the following changes:


236 changes: 131 additions & 105 deletions pybaseball/lahman.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="'"
)
Comment on lines -34 to +39
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function parks refactored with the following changes:


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="'"
)
Comment on lines -41 to +46
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function all_star_full refactored with the following changes:


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="'"
)
Comment on lines -47 to +53
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function appearances refactored with the following changes:


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="'"
)
Comment on lines -53 to +60
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function awards_managers refactored with the following changes:


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="'"
)
Comment on lines -59 to +67
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function awards_players refactored with the following changes:


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="'"
)
Comment on lines -65 to +74
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function awards_share_managers refactored with the following changes:


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="'"
)
Comment on lines -71 to +81
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function awards_share_players refactored with the following changes:


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="'"
)
Comment on lines -77 to +88
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function batting refactored with the following changes:


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="'"
)
Comment on lines -83 to +95
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function batting_post refactored with the following changes:


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="'"
)
Comment on lines -89 to +102
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function college_playing refactored with the following changes:


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="'"
)
Comment on lines -95 to +109
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function fielding refactored with the following changes:


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="'"
)
Comment on lines -101 to +116
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function fielding_of refactored with the following changes:


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="'"
)
Comment on lines -107 to +123
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function fielding_of_split refactored with the following changes:


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="'"
)
Comment on lines -113 to +130
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function fielding_post refactored with the following changes:


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="'"
)
Comment on lines -119 to +137
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function hall_of_fame refactored with the following changes:


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="'"
)
Comment on lines -125 to +144
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function home_games refactored with the following changes:


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="'"
)
Comment on lines -131 to +151
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function managers refactored with the following changes:


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="'"
)
Comment on lines -137 to +158
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function managers_half refactored with the following changes:


# 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="'"
)
Comment on lines -147 to +169
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function people refactored with the following changes:


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="'"
)
Comment on lines -153 to +176
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function pitching refactored with the following changes:


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="'"
)
Comment on lines -159 to +183
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function pitching_post refactored with the following changes:


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="'"
)
Comment on lines -165 to +190
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function salaries refactored with the following changes:


def schools():
z = get_lahman_zip()
Expand All @@ -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="'"
)
Comment on lines -177 to +203
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function series_post refactored with the following changes:


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="'"
)
Comment on lines -183 to +210
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function teams refactored with the following changes:


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="'"
)
Comment on lines -189 to +217
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function teams_franchises refactored with the following changes:


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="'"
)
Comment on lines -195 to +224
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function teams_half refactored with the following changes:


9 changes: 4 additions & 5 deletions pybaseball/league_batting_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
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]
9 changes: 4 additions & 5 deletions pybaseball/league_pitching_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Comment on lines -121 to +124
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function bwar_pitch refactored with the following changes:

3 changes: 1 addition & 2 deletions pybaseball/pitching_leaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function pitching_stats refactored with the following changes:

4 changes: 1 addition & 3 deletions pybaseball/playerid_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function playerid_lookup refactored with the following changes:

last = player.split(",")[0].strip()
first = None
if (len(player.split(",")) > 1):
Expand All @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions pybaseball/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function plot_stadium refactored with the following changes:

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(
Expand All @@ -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):
Expand Down
Loading