nbastatpy 0.1.6__py3-none-any.whl → 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of nbastatpy might be problematic. Click here for more details.
- nbastatpy/__init__.py +17 -1
- nbastatpy/config.py +445 -0
- nbastatpy/game.py +131 -30
- nbastatpy/player.py +58 -22
- nbastatpy/season.py +272 -50
- nbastatpy/standardize.py +529 -0
- nbastatpy/team.py +49 -16
- nbastatpy/utils.py +30 -3
- nbastatpy/validators.py +288 -0
- nbastatpy-0.2.0.dist-info/METADATA +69 -0
- nbastatpy-0.2.0.dist-info/RECORD +14 -0
- {nbastatpy-0.1.6.dist-info → nbastatpy-0.2.0.dist-info}/WHEEL +2 -1
- nbastatpy-0.2.0.dist-info/top_level.txt +1 -0
- nbastatpy-0.1.6.dist-info/METADATA +0 -67
- nbastatpy-0.1.6.dist-info/RECORD +0 -10
- {nbastatpy-0.1.6.dist-info → nbastatpy-0.2.0.dist-info/licenses}/LICENSE +0 -0
nbastatpy/__init__.py
CHANGED
|
@@ -1 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
from nbastatpy.game import Game
|
|
2
|
+
from nbastatpy.player import Player
|
|
3
|
+
from nbastatpy.season import Season
|
|
4
|
+
from nbastatpy.standardize import standardize_dataframe
|
|
5
|
+
from nbastatpy.team import Team
|
|
6
|
+
from nbastatpy.validators import validate_dataframe
|
|
7
|
+
|
|
8
|
+
name = "nbastatpy"
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"Player",
|
|
12
|
+
"Game",
|
|
13
|
+
"Season",
|
|
14
|
+
"Team",
|
|
15
|
+
"standardize_dataframe",
|
|
16
|
+
"validate_dataframe",
|
|
17
|
+
]
|
nbastatpy/config.py
ADDED
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
from typing import Dict, List, Set
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class ColumnTypes:
|
|
5
|
+
"""Standard column type mappings for common NBA data fields."""
|
|
6
|
+
|
|
7
|
+
# Numeric types - Integer columns
|
|
8
|
+
INTEGER_COLUMNS: Set[str] = {
|
|
9
|
+
# Basic info
|
|
10
|
+
"age",
|
|
11
|
+
"season_year",
|
|
12
|
+
"draft_year",
|
|
13
|
+
"draft_round",
|
|
14
|
+
"draft_number",
|
|
15
|
+
# Games and results
|
|
16
|
+
"games",
|
|
17
|
+
"games_played",
|
|
18
|
+
"gp",
|
|
19
|
+
"gs",
|
|
20
|
+
"games_started",
|
|
21
|
+
"w",
|
|
22
|
+
"l",
|
|
23
|
+
"wins",
|
|
24
|
+
"losses",
|
|
25
|
+
"win_streak",
|
|
26
|
+
"lose_streak",
|
|
27
|
+
# Traditional stats - field goals
|
|
28
|
+
"fgm",
|
|
29
|
+
"fga",
|
|
30
|
+
"fg3m",
|
|
31
|
+
"fg3a",
|
|
32
|
+
"fg2m",
|
|
33
|
+
"fg2a",
|
|
34
|
+
"ftm",
|
|
35
|
+
"fta",
|
|
36
|
+
# Traditional stats - rebounds
|
|
37
|
+
"oreb",
|
|
38
|
+
"dreb",
|
|
39
|
+
"reb",
|
|
40
|
+
"oreb_pct_rank",
|
|
41
|
+
"dreb_pct_rank",
|
|
42
|
+
# Traditional stats - other
|
|
43
|
+
"ast",
|
|
44
|
+
"stl",
|
|
45
|
+
"blk",
|
|
46
|
+
"tov",
|
|
47
|
+
"pf",
|
|
48
|
+
"pts",
|
|
49
|
+
"plus_minus",
|
|
50
|
+
"pm",
|
|
51
|
+
# Ranking columns
|
|
52
|
+
"rank",
|
|
53
|
+
"w_rank",
|
|
54
|
+
"l_rank",
|
|
55
|
+
"w_pct_rank",
|
|
56
|
+
# Advanced stat counts
|
|
57
|
+
"contested_shots",
|
|
58
|
+
"deflections",
|
|
59
|
+
"loose_balls_recovered",
|
|
60
|
+
"charges_drawn",
|
|
61
|
+
"screen_assists",
|
|
62
|
+
"box_outs",
|
|
63
|
+
# Tracking counts
|
|
64
|
+
"touches",
|
|
65
|
+
"front_ct_touches",
|
|
66
|
+
"elbow_touches",
|
|
67
|
+
"post_touches",
|
|
68
|
+
"paint_touches",
|
|
69
|
+
"passes",
|
|
70
|
+
"ast_pass",
|
|
71
|
+
"secondary_ast",
|
|
72
|
+
"potential_ast",
|
|
73
|
+
"drives",
|
|
74
|
+
# Synergy/play type counts
|
|
75
|
+
"poss",
|
|
76
|
+
"possessions",
|
|
77
|
+
# Shot location counts
|
|
78
|
+
"restricted_area_fgm",
|
|
79
|
+
"restricted_area_fga",
|
|
80
|
+
"paint_fgm",
|
|
81
|
+
"paint_fga",
|
|
82
|
+
"midrange_fgm",
|
|
83
|
+
"midrange_fga",
|
|
84
|
+
"left_corner_three_fgm",
|
|
85
|
+
"left_corner_three_fga",
|
|
86
|
+
"right_corner_three_fgm",
|
|
87
|
+
"right_corner_three_fga",
|
|
88
|
+
"above_break_three_fgm",
|
|
89
|
+
"above_break_three_fga",
|
|
90
|
+
"corner_three_fgm",
|
|
91
|
+
"corner_three_fga",
|
|
92
|
+
"backcourt_fgm",
|
|
93
|
+
"backcourt_fga",
|
|
94
|
+
# Play-by-play
|
|
95
|
+
"period",
|
|
96
|
+
"quarter",
|
|
97
|
+
"score_margin",
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
# Float columns - Percentages, rates, and continuous metrics
|
|
101
|
+
FLOAT_COLUMNS: Set[str] = {
|
|
102
|
+
# Shooting percentages
|
|
103
|
+
"fg_pct",
|
|
104
|
+
"fg2_pct",
|
|
105
|
+
"fg3_pct",
|
|
106
|
+
"ft_pct",
|
|
107
|
+
"ts_pct",
|
|
108
|
+
"efg_pct",
|
|
109
|
+
# Advanced percentages
|
|
110
|
+
"ast_pct",
|
|
111
|
+
"ast_to",
|
|
112
|
+
"ast_ratio",
|
|
113
|
+
"reb_pct",
|
|
114
|
+
"oreb_pct",
|
|
115
|
+
"dreb_pct",
|
|
116
|
+
"usg_pct",
|
|
117
|
+
"tov_pct",
|
|
118
|
+
"stl_pct",
|
|
119
|
+
"blk_pct",
|
|
120
|
+
"tm_tov_pct",
|
|
121
|
+
# Win/pace metrics
|
|
122
|
+
"w_pct",
|
|
123
|
+
"pace",
|
|
124
|
+
"pie",
|
|
125
|
+
"net_rating",
|
|
126
|
+
"off_rating",
|
|
127
|
+
"def_rating",
|
|
128
|
+
"ortg",
|
|
129
|
+
"drtg",
|
|
130
|
+
# Time metrics
|
|
131
|
+
"min",
|
|
132
|
+
"minutes",
|
|
133
|
+
"min_pct",
|
|
134
|
+
"time_of_poss",
|
|
135
|
+
"avg_sec_per_touch",
|
|
136
|
+
"avg_drib_per_touch",
|
|
137
|
+
# Physical measurements
|
|
138
|
+
"height_inches",
|
|
139
|
+
"weight",
|
|
140
|
+
# Distance metrics
|
|
141
|
+
"dist_feet",
|
|
142
|
+
"dist_miles",
|
|
143
|
+
"avg_speed",
|
|
144
|
+
"avg_speed_off",
|
|
145
|
+
"avg_speed_def",
|
|
146
|
+
# Shot location percentages
|
|
147
|
+
"restricted_area_fg_pct",
|
|
148
|
+
"paint_fg_pct",
|
|
149
|
+
"midrange_fg_pct",
|
|
150
|
+
"left_corner_three_fg_pct",
|
|
151
|
+
"right_corner_three_fg_pct",
|
|
152
|
+
"above_break_three_fg_pct",
|
|
153
|
+
"corner_three_fg_pct",
|
|
154
|
+
"backcourt_fg_pct",
|
|
155
|
+
# Shot type percentages
|
|
156
|
+
"catch_shoot_fg_pct",
|
|
157
|
+
"pull_up_fg_pct",
|
|
158
|
+
"less_than_6_fg_pct",
|
|
159
|
+
"less_than_10_fg_pct",
|
|
160
|
+
"greater_than_15_fg_pct",
|
|
161
|
+
# Four factors
|
|
162
|
+
"efg_pct_rank",
|
|
163
|
+
"fta_rate",
|
|
164
|
+
"tm_tov_pct_rank",
|
|
165
|
+
"oreb_pct_rank_val",
|
|
166
|
+
# Synergy metrics
|
|
167
|
+
"percentile",
|
|
168
|
+
"ppp",
|
|
169
|
+
"points_per_possession",
|
|
170
|
+
"freq",
|
|
171
|
+
"frequency",
|
|
172
|
+
# Passing metrics
|
|
173
|
+
"ast_pts_created",
|
|
174
|
+
"ast_adj",
|
|
175
|
+
"passes_made",
|
|
176
|
+
"passes_received",
|
|
177
|
+
# Matchup metrics
|
|
178
|
+
"partial_poss",
|
|
179
|
+
"player_pts",
|
|
180
|
+
"matchup_ast",
|
|
181
|
+
"matchup_tov",
|
|
182
|
+
"matchup_blk",
|
|
183
|
+
"matchup_fgm",
|
|
184
|
+
"matchup_fga",
|
|
185
|
+
"matchup_fg_pct",
|
|
186
|
+
"help_blk",
|
|
187
|
+
"help_blk_pct",
|
|
188
|
+
# Defense metrics
|
|
189
|
+
"dfg_pct",
|
|
190
|
+
"diff_pct",
|
|
191
|
+
"normal_fg_pct",
|
|
192
|
+
# Salary
|
|
193
|
+
"salary",
|
|
194
|
+
"adj_salary",
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
# String types
|
|
198
|
+
STRING_COLUMNS: Set[str] = {
|
|
199
|
+
# Player info
|
|
200
|
+
"player_name",
|
|
201
|
+
"player_first_name",
|
|
202
|
+
"player_last_name",
|
|
203
|
+
"first_name",
|
|
204
|
+
"last_name",
|
|
205
|
+
"display_first_last",
|
|
206
|
+
"display_last_comma_first",
|
|
207
|
+
"display_fi_last",
|
|
208
|
+
"player_slug",
|
|
209
|
+
# Team info
|
|
210
|
+
"team_name",
|
|
211
|
+
"team_abbreviation",
|
|
212
|
+
"team_slug",
|
|
213
|
+
"team_city",
|
|
214
|
+
"team_nickname",
|
|
215
|
+
"abbrev",
|
|
216
|
+
# Position
|
|
217
|
+
"position",
|
|
218
|
+
"pos",
|
|
219
|
+
"player_position",
|
|
220
|
+
# Geographic info
|
|
221
|
+
"college",
|
|
222
|
+
"country",
|
|
223
|
+
"birthplace",
|
|
224
|
+
"school",
|
|
225
|
+
# Game info
|
|
226
|
+
"matchup",
|
|
227
|
+
"wl",
|
|
228
|
+
"video_available",
|
|
229
|
+
# Lineup info
|
|
230
|
+
"group_name",
|
|
231
|
+
"group_id",
|
|
232
|
+
# Matchup strings
|
|
233
|
+
"off_player_name",
|
|
234
|
+
"def_player_name",
|
|
235
|
+
# Play type
|
|
236
|
+
"play_type",
|
|
237
|
+
"type_grouping",
|
|
238
|
+
# General categorical
|
|
239
|
+
"season_type",
|
|
240
|
+
"season_type_all_star",
|
|
241
|
+
"is_playoffs",
|
|
242
|
+
"outcome",
|
|
243
|
+
"location",
|
|
244
|
+
# Additional identifiers
|
|
245
|
+
"nickname",
|
|
246
|
+
"rosterstatus",
|
|
247
|
+
"how_acquired",
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
class IDFields:
|
|
252
|
+
"""Registry of ID fields and their standardization rules."""
|
|
253
|
+
|
|
254
|
+
# Fields that should be zero-padded to 10 digits
|
|
255
|
+
ID_FIELDS: Set[str] = {
|
|
256
|
+
"player_id",
|
|
257
|
+
"team_id",
|
|
258
|
+
"game_id",
|
|
259
|
+
"person_id",
|
|
260
|
+
"playerid",
|
|
261
|
+
"teamid",
|
|
262
|
+
"gameid",
|
|
263
|
+
"personid",
|
|
264
|
+
"off_player_id",
|
|
265
|
+
"def_player_id",
|
|
266
|
+
"vs_player_id",
|
|
267
|
+
"player1_id",
|
|
268
|
+
"player2_id",
|
|
269
|
+
"player3_id",
|
|
270
|
+
"player4_id",
|
|
271
|
+
"player5_id",
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
# Mapping of inconsistent ID field names to standardized names
|
|
275
|
+
ID_FIELD_MAPPING: Dict[str, str] = {
|
|
276
|
+
"gameid": "game_id",
|
|
277
|
+
"teamid": "team_id",
|
|
278
|
+
"playerid": "player_id",
|
|
279
|
+
"person_id": "player_id",
|
|
280
|
+
"personid": "player_id",
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
class DateFields:
|
|
285
|
+
"""Registry of date fields and parsing formats."""
|
|
286
|
+
|
|
287
|
+
# Fields that should be parsed as dates
|
|
288
|
+
DATE_FIELDS: Set[str] = {
|
|
289
|
+
"game_date",
|
|
290
|
+
"birthdate",
|
|
291
|
+
"birth_date",
|
|
292
|
+
"from_year",
|
|
293
|
+
"to_year",
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
# Date parsing formats to try (in order)
|
|
297
|
+
DATE_FORMATS: List[str] = [
|
|
298
|
+
"%Y-%m-%dT%H:%M:%S", # ISO with time
|
|
299
|
+
"%Y-%m-%d", # ISO date
|
|
300
|
+
"%m/%d/%Y", # US format
|
|
301
|
+
"%d/%m/%Y", # International format
|
|
302
|
+
]
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
class TimeFields:
|
|
306
|
+
"""Registry of time fields that need conversion."""
|
|
307
|
+
|
|
308
|
+
# Fields in MM:SS format that should be converted to seconds
|
|
309
|
+
MINUTES_SECONDS_FIELDS: Set[str] = {
|
|
310
|
+
"min",
|
|
311
|
+
"minutes",
|
|
312
|
+
"matchupminutes",
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
# Fields that represent seconds already
|
|
316
|
+
SECONDS_FIELDS: Set[str] = {
|
|
317
|
+
"seconds",
|
|
318
|
+
"matchup_seconds",
|
|
319
|
+
"clock_seconds",
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
class SpecialFields:
|
|
324
|
+
"""Special field handling rules."""
|
|
325
|
+
|
|
326
|
+
# Fields that indicate playoff vs regular season
|
|
327
|
+
PLAYOFF_INDICATORS: Set[str] = {
|
|
328
|
+
"season_type",
|
|
329
|
+
"season_type_all_star",
|
|
330
|
+
"is_playoffs",
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
# Height fields (in feet-inches format like "6-11")
|
|
334
|
+
HEIGHT_FIELDS: Set[str] = {
|
|
335
|
+
"height",
|
|
336
|
+
"player_height",
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
# Weight fields (in pounds)
|
|
340
|
+
WEIGHT_FIELDS: Set[str] = {
|
|
341
|
+
"weight",
|
|
342
|
+
"player_weight",
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
# Matchup fields that need parsing (e.g., "TOR @ BOS")
|
|
346
|
+
MATCHUP_FIELDS: Set[str] = {
|
|
347
|
+
"matchup",
|
|
348
|
+
"game_matchup",
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
# Win/Loss indicator fields
|
|
352
|
+
WL_FIELDS: Set[str] = {
|
|
353
|
+
"wl",
|
|
354
|
+
"w_l",
|
|
355
|
+
"outcome",
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
# Lineup/group name fields that contain player names
|
|
359
|
+
LINEUP_FIELDS: Set[str] = {
|
|
360
|
+
"group_name",
|
|
361
|
+
"lineup",
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
# Fields that should be added during standardization
|
|
365
|
+
METADATA_FIELDS: Set[str] = {
|
|
366
|
+
"standardized_at",
|
|
367
|
+
"source_endpoint",
|
|
368
|
+
"data_type",
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
# Salary fields that need currency cleaning
|
|
372
|
+
SALARY_FIELDS: Set[str] = {
|
|
373
|
+
"salary",
|
|
374
|
+
"adj_salary",
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
class TableConfigs:
|
|
379
|
+
"""Table-specific configuration rules."""
|
|
380
|
+
|
|
381
|
+
# Player endpoints that return player data
|
|
382
|
+
PLAYER_ENDPOINTS: Set[str] = {
|
|
383
|
+
"commonplayerinfo",
|
|
384
|
+
"playercareerstats",
|
|
385
|
+
"playerdashboardbygeneralsplits",
|
|
386
|
+
"playerdashboardbygamesplits",
|
|
387
|
+
"playerdashboardbyshootingsplits",
|
|
388
|
+
"playerawards",
|
|
389
|
+
"playergamelog",
|
|
390
|
+
"draftcombinestats",
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
# Game endpoints
|
|
394
|
+
GAME_ENDPOINTS: Set[str] = {
|
|
395
|
+
"boxscoretraditionalv3",
|
|
396
|
+
"boxscoreadvancedv3",
|
|
397
|
+
"boxscoredefensivev2",
|
|
398
|
+
"boxscorefourfactorsv3",
|
|
399
|
+
"boxscorehustlev2",
|
|
400
|
+
"boxscorematchupsv3",
|
|
401
|
+
"boxscoremiscv3",
|
|
402
|
+
"boxscorescoringv3",
|
|
403
|
+
"boxscoreusagev3",
|
|
404
|
+
"boxscoreplayertrackv3",
|
|
405
|
+
"gamerotation",
|
|
406
|
+
"playbyplayv3",
|
|
407
|
+
"winprobabilitypbp",
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
# Season endpoints
|
|
411
|
+
SEASON_ENDPOINTS: Set[str] = {
|
|
412
|
+
"leaguedashlineups",
|
|
413
|
+
"leaguelineupviz",
|
|
414
|
+
"leaguedashopppptshot",
|
|
415
|
+
"leaguedashplayerclutch",
|
|
416
|
+
"leaguedashplayerptshot",
|
|
417
|
+
"leaguedashplayershotlocations",
|
|
418
|
+
"leaguedashplayerstats",
|
|
419
|
+
"leaguedashteamclutch",
|
|
420
|
+
"leaguedashteamptshot",
|
|
421
|
+
"leaguedashteamshotlocations",
|
|
422
|
+
"leaguedashteamstats",
|
|
423
|
+
"playergamelogs",
|
|
424
|
+
"leaguegamelog",
|
|
425
|
+
"leaguehustlestatsplayer",
|
|
426
|
+
"leaguehustlestatsteam",
|
|
427
|
+
"leagueseasonmatchups",
|
|
428
|
+
"playerestimatedmetrics",
|
|
429
|
+
"synergyplaytypes",
|
|
430
|
+
"leaguedashptstats",
|
|
431
|
+
"leaguedashptdefend",
|
|
432
|
+
"leaguedashptteamdefend",
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
# Team endpoints
|
|
436
|
+
TEAM_ENDPOINTS: Set[str] = {
|
|
437
|
+
"commonteamroster",
|
|
438
|
+
"teamyearbyyearstats",
|
|
439
|
+
"teamdashboardbygeneralsplits",
|
|
440
|
+
"teamdashboardbyshootingsplits",
|
|
441
|
+
"franchiseleaders",
|
|
442
|
+
"franchiseplayers",
|
|
443
|
+
"teamdashptpass",
|
|
444
|
+
"teamplayeronoffdetails",
|
|
445
|
+
}
|