nba_api
nba_api copied to clipboard
CumeStatsPlayer does not work.
CumeStatsPlayer doesn't seem to be working properly.
It requires a list of GameIDs, which are provided when I fetch all game IDs for a certain player's season (in this case, Jason Tatum 2021-22). Despite giving a ton of GameIDs, I only get the totals for 1 game? I am confused. It even says GP/GS are both values of 1 in the response.
Below is what I am executing:
from nba_api.stats.endpoints import commonplayerinfo, cumestatsplayer, cumestatsplayergames
from nba_api.stats.static import players;
# nba_players = players.get_players()
nba_players = players.find_players_by_full_name('Jayson Tatum')
for nba_player in nba_players:
player_id = nba_player['id']
player_info = commonplayerinfo.CommonPlayerInfo(player_id).common_player_info.get_dict()
p_columns = player_info['headers']
p_rows = player_info['data'][0]
p_data = dict(zip(p_columns, p_rows))
print(p_data)
p_games = cumestatsplayergames.CumeStatsPlayerGames(player_id, league_id='00', season='2021-22', season_type_all_star='Regular Season').cume_stats_player_games.get_dict()['data']
game_ids = []
for game in p_games:
game_ids.append(game[1])
print(game_ids)
p_stats = cumestatsplayer.CumeStatsPlayer(player_id, game_ids, league_id='00', season='2021-22').total_player_stats.get_dict()
pstats_columns = p_stats['headers']
pstats_rows = p_stats['data'][0]
pstats_data = dict(zip(pstats_columns, pstats_rows))
print('\n\n')
print('player stats: ')
print(pstats_data)
Even putting hand-picked game IDs into the game_ids parameter gives me the same result, cumulative stats for only 1 game despite giving a bunch of game IDs that are valid.
@YKhanTU: The game_ids should be formatted as 0022200186|0022200176|0022200163|0022200152
Here's a valid URL:
https://stats.nba.com/stats/cumestatsplayer?LeagueID=00&Season=2022-23&SeasonType=Regular Season&PlayerID=1628369&gameIDs=0022200186|0022200176|0022200163|0022200152
Actual Site: https://www.nba.com/stats/cumestats?ReportType=Player&PlayerID=1628369
You can use the browsers Dev Tools to view the call.
All that being said, I think we could certainly make this more clear, or put in an option that simply takes a dictionary in; that would have been my first thought.
Hope that helps.
@YKhanTU: The game_ids should be formatted as
0022200186|0022200176|0022200163|0022200152
Here's a valid URL:
https://stats.nba.com/stats/cumestatsplayer?LeagueID=00&Season=2022-23&SeasonType=Regular Season&PlayerID=1628369&gameIDs=0022200186|0022200176|0022200163|0022200152
Actual Site: https://www.nba.com/stats/cumestats?ReportType=Player&PlayerID=1628369
You can use the browsers Dev Tools to view the call.
All that being said, I think we could certainly make this more clear, or put in an option that simply takes a dictionary in; that would have been my first thought.
Hope that helps.
Awesome. I didn't realize it needed to be formatted in that way. That would be nice if we could pass in an array or dictionary in as well.
Thanks for the help.
I am having trouble even using one game id. I tried multiple ones with the format you suggested and it also does not work. This line returns an error. from nba_api.stats.endpoints import cumestatsplayer cumestatsplayer.CumeStatsPlayer(game_ids='22001069', player_id=1630173, season='2020-21', season_type_all_star='Regular Season')
I tried just using the game_ids as a single value thats not a string. I tried using your format hoping multiple games would return something like so : game_ids='22001069|22001062'.
I have had no other trouble with your other endpoints I have used so far.
Here is the error that comes up.
Traceback (most recent call last):
File "", line 1, in
At least of now, it's probably best to update the documentation for this endpoint. It's unclear that the required input format is 1. a string and 2. the string needs to follow the format 'game_id_0|game_id_1|game_id2'
.
Secondly, this is probably an implementation detail that can be handled by the CumeStatsPlayer
endpoint and just expect a list or a set as input to the game_ids parameter.