nbastatpy 0.1.8__tar.gz → 0.2.0__tar.gz

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.

Files changed (30) hide show
  1. nbastatpy-0.2.0/PKG-INFO +69 -0
  2. nbastatpy-0.2.0/README.md +50 -0
  3. {nbastatpy-0.1.8 → nbastatpy-0.2.0}/pyproject.toml +27 -3
  4. nbastatpy-0.2.0/src/nbastatpy/__init__.py +17 -0
  5. nbastatpy-0.2.0/src/nbastatpy/config.py +445 -0
  6. nbastatpy-0.2.0/src/nbastatpy/game.py +254 -0
  7. {nbastatpy-0.1.8 → nbastatpy-0.2.0}/src/nbastatpy/player.py +58 -22
  8. {nbastatpy-0.1.8 → nbastatpy-0.2.0}/src/nbastatpy/season.py +272 -50
  9. nbastatpy-0.2.0/src/nbastatpy/standardize.py +529 -0
  10. {nbastatpy-0.1.8 → nbastatpy-0.2.0}/src/nbastatpy/team.py +49 -16
  11. {nbastatpy-0.1.8 → nbastatpy-0.2.0}/src/nbastatpy/utils.py +30 -3
  12. nbastatpy-0.2.0/src/nbastatpy/validators.py +288 -0
  13. nbastatpy-0.2.0/src/nbastatpy.egg-info/PKG-INFO +69 -0
  14. {nbastatpy-0.1.8 → nbastatpy-0.2.0}/src/nbastatpy.egg-info/SOURCES.txt +6 -1
  15. {nbastatpy-0.1.8 → nbastatpy-0.2.0}/tests/test_season.py +1 -1
  16. nbastatpy-0.2.0/tests/test_standardize.py +237 -0
  17. nbastatpy-0.2.0/tests/test_validators.py +231 -0
  18. nbastatpy-0.1.8/PKG-INFO +0 -59
  19. nbastatpy-0.1.8/README.md +0 -41
  20. nbastatpy-0.1.8/src/nbastatpy/__init__.py +0 -1
  21. nbastatpy-0.1.8/src/nbastatpy/game.py +0 -153
  22. nbastatpy-0.1.8/src/nbastatpy.egg-info/PKG-INFO +0 -59
  23. {nbastatpy-0.1.8 → nbastatpy-0.2.0}/LICENSE +0 -0
  24. {nbastatpy-0.1.8 → nbastatpy-0.2.0}/setup.cfg +0 -0
  25. {nbastatpy-0.1.8 → nbastatpy-0.2.0}/src/nbastatpy.egg-info/dependency_links.txt +0 -0
  26. {nbastatpy-0.1.8 → nbastatpy-0.2.0}/src/nbastatpy.egg-info/requires.txt +0 -0
  27. {nbastatpy-0.1.8 → nbastatpy-0.2.0}/src/nbastatpy.egg-info/top_level.txt +0 -0
  28. {nbastatpy-0.1.8 → nbastatpy-0.2.0}/tests/test_game.py +0 -0
  29. {nbastatpy-0.1.8 → nbastatpy-0.2.0}/tests/test_player.py +0 -0
  30. {nbastatpy-0.1.8 → nbastatpy-0.2.0}/tests/test_team.py +0 -0
@@ -0,0 +1,69 @@
1
+ Metadata-Version: 2.4
2
+ Name: nbastatpy
3
+ Version: 0.2.0
4
+ Summary: An easy-to-use wrapper for nba_api to easily find data for a player, game, team, or season
5
+ Keywords: basketball,data,nba,sports,stats
6
+ Classifier: Intended Audience :: Science/Research
7
+ Classifier: License :: OSI Approved :: MIT License
8
+ Requires-Python: >=3.10
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: bs4>=0.0.2
12
+ Requires-Dist: loguru>=0.7.3
13
+ Requires-Dist: nba-api>=1.6.1
14
+ Requires-Dist: pandas>=2.2.3
15
+ Requires-Dist: pillow>=11.0.0
16
+ Requires-Dist: requests>=2.32.3
17
+ Requires-Dist: rich>=13.9.4
18
+ Dynamic: license-file
19
+
20
+ # NBAStatPy
21
+
22
+ [![PyPI version](https://badge.fury.io/py/nbastatpy.svg)](https://badge.fury.io/py/nbastatpy)
23
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
24
+ [![CI](https://github.com/aberghammer-analytics/NBAStatPy/workflows/Run%20Pytest/badge.svg)](https://github.com/aberghammer-analytics/NBAStatPy/actions)
25
+
26
+ ## Overview
27
+
28
+ A simple, easy-to-use wrapper for the `nba_api` package to access NBA data for players, games, teams, and seasons.
29
+
30
+ ## Quick Start
31
+
32
+ ```python
33
+ from nbastatpy.player import Player
34
+
35
+ # Create a player object
36
+ player = Player("Giannis", season="2023", playoffs=True)
37
+
38
+ # Get data
39
+ awards = player.get_awards()
40
+ stats = player.get_career_stats()
41
+ ```
42
+
43
+ ## Main Classes
44
+
45
+ - **Player** - Access player stats, career data, and awards
46
+ - **Game** - Get boxscores, play-by-play, and game details
47
+ - **Season** - Query league-wide stats, lineups, and tracking data
48
+ - **Team** - Retrieve team rosters, stats, and splits
49
+
50
+
51
+ ### Standalone Usage
52
+
53
+ ```python
54
+ from nbastatpy.standardize import standardize_dataframe
55
+
56
+ df = standardize_dataframe(df, data_type='player')
57
+ ```
58
+
59
+ ## Installation
60
+
61
+ ### Pip
62
+ ```bash
63
+ pip install nbastatpy
64
+ ```
65
+
66
+ ### UV
67
+ ```bash
68
+ uv add nbastatpy
69
+ ```
@@ -0,0 +1,50 @@
1
+ # NBAStatPy
2
+
3
+ [![PyPI version](https://badge.fury.io/py/nbastatpy.svg)](https://badge.fury.io/py/nbastatpy)
4
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
5
+ [![CI](https://github.com/aberghammer-analytics/NBAStatPy/workflows/Run%20Pytest/badge.svg)](https://github.com/aberghammer-analytics/NBAStatPy/actions)
6
+
7
+ ## Overview
8
+
9
+ A simple, easy-to-use wrapper for the `nba_api` package to access NBA data for players, games, teams, and seasons.
10
+
11
+ ## Quick Start
12
+
13
+ ```python
14
+ from nbastatpy.player import Player
15
+
16
+ # Create a player object
17
+ player = Player("Giannis", season="2023", playoffs=True)
18
+
19
+ # Get data
20
+ awards = player.get_awards()
21
+ stats = player.get_career_stats()
22
+ ```
23
+
24
+ ## Main Classes
25
+
26
+ - **Player** - Access player stats, career data, and awards
27
+ - **Game** - Get boxscores, play-by-play, and game details
28
+ - **Season** - Query league-wide stats, lineups, and tracking data
29
+ - **Team** - Retrieve team rosters, stats, and splits
30
+
31
+
32
+ ### Standalone Usage
33
+
34
+ ```python
35
+ from nbastatpy.standardize import standardize_dataframe
36
+
37
+ df = standardize_dataframe(df, data_type='player')
38
+ ```
39
+
40
+ ## Installation
41
+
42
+ ### Pip
43
+ ```bash
44
+ pip install nbastatpy
45
+ ```
46
+
47
+ ### UV
48
+ ```bash
49
+ uv add nbastatpy
50
+ ```
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "nbastatpy"
3
- version = "0.1.8"
3
+ version = "0.2.0" # Managed by release-please
4
4
  description = "An easy-to-use wrapper for nba_api to easily find data for a player, game, team, or season"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -20,14 +20,38 @@ classifiers = [
20
20
  ]
21
21
 
22
22
 
23
- [tool.uv]
24
- dev-dependencies = [
23
+ [dependency-groups]
24
+ dev = [
25
25
  "black>=24.10.0",
26
26
  "ipykernel>=6.29.5",
27
27
  "ruff>=0.8.2",
28
28
  "pytest>=8.3.4",
29
+ "pytest-cov>=6.0.0",
30
+ "pytest-mock>=3.14.0",
31
+ "mypy>=1.13.0",
32
+ "pre-commit>=4.0.1",
33
+ "safety>=3.2.11",
29
34
  ]
30
35
 
31
36
  [tool.pytest.ini_options]
32
37
  pythonpath = ["src"]
38
+ testpaths = ["tests"]
39
+ addopts = [
40
+ "--strict-markers",
41
+ "--strict-config",
42
+ "-ra",
43
+ ]
44
+
45
+ [tool.coverage.run]
46
+ source = ["src"]
47
+ branch = true
48
+ omit = [
49
+ "*/tests/*",
50
+ "*/__pycache__/*",
51
+ "*/build/*",
52
+ ]
33
53
 
54
+ [tool.coverage.report]
55
+ precision = 2
56
+ show_missing = true
57
+ skip_covered = false
@@ -0,0 +1,17 @@
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
+ ]
@@ -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
+ }