-
Notifications
You must be signed in to change notification settings - Fork 8
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
# 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
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="'" | ||
) | ||
Comment on lines
-177
to
+203
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
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: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
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): | ||
|
There was a problem hiding this comment.
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:inline-immediately-returned-variable
)