Skip to content

Conversation

@SourceryAI
Copy link

Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨

Here's your pull request refactoring your most popular Python repo.

If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch https://github.com/sourcery-ai-bot/pybaseball master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Comment on lines -6 to +7
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)
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:

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:

Comment on lines -34 to +39
# 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="'"
)
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:

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

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

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

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

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

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

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

Comment on lines -147 to +169
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="'"
)
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:

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

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

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

Comment on lines -177 to +203
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="'"
)
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 get_tables(soup, season):
datasets = []
if(season>=1969):
if (season>=1969):
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_tables refactored with the following changes:

Comment on lines -75 to +76
elif season<=1904: code = BeautifulSoup(t[15], "lxml")
else:
code = BeautifulSoup(t[15], "lxml")
Copy link
Author

Choose a reason for hiding this comment

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

Function standings refactored with the following changes:

Comment on lines -187 to -188
# 3 days or less -> a quick one-shot request. Greater than 3 days -> break it into multiple smaller queries
small_query_threshold = 5
Copy link
Author

Choose a reason for hiding this comment

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

Function statcast refactored with the following changes:

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)
Copy link
Author

Choose a reason for hiding this comment

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

Function statcast_batter refactored with the following changes:

Comment on lines -25 to +24
data = pd.read_csv(io.StringIO(res.decode('utf-8')))
return data
return pd.read_csv(io.StringIO(res.decode('utf-8')))
Copy link
Author

Choose a reason for hiding this comment

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

Function statcast_batter_exitvelo_barrels refactored with the following changes:

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)
Copy link
Author

Choose a reason for hiding this comment

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

Function statcast_pitcher refactored with the following changes:

Comment on lines -48 to -50
else:
pass

Copy link
Author

Choose a reason for hiding this comment

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

Function postprocessing refactored with the following changes:

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]
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_table refactored with the following changes:

Comment on lines -5 to +13
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:
Copy link
Author

Choose a reason for hiding this comment

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

Function top_prospects refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant