PandasBasketball
PandasBasketball copied to clipboard
Fixed Collisions in generate_code() Method
Hello Alfredo!
Love PandasBasketball. But I noticed some bugs with the pandasbasketball.generate_code()
method and thought I could contribute.
Issues with master branch:
- If user inputs non-ascii characters such as
get_player("Greivis Vásquez")
, pb returnsstatuscode.404
- If user inputs player with more than two names, such as
get_player("James Michael McAdoo")
, pb returns 'ValueError' - If user inputs player who shares the same first 5 letters of last name and first 2 letters of first name with another player, such as
get_player("JaKarr Sampson")
, pb returns DF with stats for Jamal Sampson.
My code:
- Works by finding the page listing all the players with a last name starting with the same letter the user-inputted last name and then finding the latter part of the URL for that player's stats page
- Fixes (1) as long as non-ascii characters aren't the first letter of the last name
- Fixes (2) except in cases where player's apparent middle name is actually the beginning of their last name, such as Luc Mbah a Moute
- Fixes (3) completely
- Retains the original method as a backup in case a user wants to type in ascii characters for a foreign player
- Makes a slight change to
errors.StatusCode404
to let user know the source of the issue might have been a mis-typed player name
It should be a strict improvement (not introduce any bugs that weren't already present).
Thanks! Let me know what you think.