Skip to content

fix(baseball): correct player position and free_agents position filter - #687

Merged
cwendt94 merged 1 commit into
cwendt94:masterfrom
gdifiore:fix/position-map-free-agents
Mar 23, 2026
Merged

fix(baseball): correct player position and free_agents position filter#687
cwendt94 merged 1 commit into
cwendt94:masterfrom
gdifiore:fix/position-map-free-agents

Conversation

@gdifiore

@gdifiore gdifiore commented Mar 21, 2026

Copy link
Copy Markdown
Contributor

Player.position used POSITION_MAP (lineup slot IDs) with a -1 offset to resolve defaultPositionId, causing wrong positions for nearly every player (e.g. Bryan Woo: C instead of SP). The two ID systems are unrelated — defaultPositionId=1 means SP, but lineup slot 0 is C.

  • Fixes this by introducing DEFAULT_POSITION_MAP, which maps defaultPositionId directly to position strings.
  • Also adds the missing reverse str→int entries to POSITION_MAP (previously # reverse TODO), enabling free_agents(position=...) to correctly filter by lineup slot ID. Without them, the position filter was silently ignored.

Reproducible PoC:

from espn_api.baseball import League

league = League(LEAGUE_ID, YEAR, espn_s2=ESPN_S2, swid=SWID)

# Bug 1: Player.position — pitchers show wrong position
pitchers = [p for team in league.teams for p in team.roster if p.lineupSlot == 'P']
print([p.position for p in pitchers[:3]])  # expected SP/RP

# Bug 2: free_agents(position=...) filter silently ignored
sps = league.free_agents(size=5, position='SP')
print([p.position for p in sps])  # expected all SP

Player.position was using POSITION_MAP (lineupSlotId numbering) with a
-1 offset to look up defaultPositionId, causing pitchers and position
players to map to the wrong position (e.g. SP→C, RP→DH).

Fix by introducing DEFAULT_POSITION_MAP which maps defaultPositionId
directly to position strings — a separate numbering system from the
lineup slot IDs in POSITION_MAP.

Also completes the reverse str→int entries in POSITION_MAP (previously
marked '# reverse TODO'), enabling free_agents(position=...) to
correctly filter by lineup slot ID.
@codecov

codecov Bot commented Mar 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.09%. Comparing base (b4c6148) to head (40feee9).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #687      +/-   ##
==========================================
+ Coverage   71.06%   71.09%   +0.02%     
==========================================
  Files          62       62              
  Lines        2426     2425       -1     
==========================================
  Hits         1724     1724              
+ Misses        702      701       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cwendt94

Copy link
Copy Markdown
Owner

Thanks for fixing this issue and adding unit tests!

@cwendt94
cwendt94 merged commit 0fd5d55 into cwendt94:master Mar 23, 2026
3 checks passed
gdifiore pushed a commit to gdifiore/espn-api that referenced this pull request Mar 26, 2026
…gents

fix(baseball): correct player position and free_agents position filter
gdifiore pushed a commit to gdifiore/espn-api that referenced this pull request Mar 26, 2026
…gents

fix(baseball): correct player position and free_agents position filter
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.

2 participants