[GH-ISSUE #703] Club names and aliases not correctly mapped at teamname_replacements.json #148

Closed
opened 2026-03-02 15:56:12 +03:00 by kerem · 2 comments
Owner

Originally created by @MartiONE on GitHub (Sep 12, 2024).
Original GitHub issue: https://github.com/probberechts/soccerdata/issues/703

Describe the bug
The bug appears when you try to call read_team_history from ClubElo. The file that contains aliases for team names that might differ from the ClubElo website gets correctly loaded and stored inside the _config.py variable TEAMNAME_REPLACEMENTS.
However, whenever the function read_team_history inside the ClubElo class tries to filter the names to process does it in the reverse way, the problematic line is this one

Affected scrapers
This affects the following scrapers:

  • ClubElo
  • ESPN
  • FBref
  • FiveThirtyEight
  • FotMob
  • Match History
  • SoFIFA
  • Understat
  • WhoScored

Code example
Considering you have a minimal teamname_replacements.json like

{"Tottenham": ["Tottenham Hotspur", "Tottenham Hotspur FC", "Spurs"]}

and then you run

import soccerdata as sd
elo = sd.ClubElo()
elo.read_team_history(team="Spurs")

Error message

ValueError                                Traceback (most recent call last)
Cell In[4], [line 1](vscode-notebook-cell:?execution_count=4&line=1)
----> [1](vscode-notebook-cell:?execution_count=4&line=1) elo.read_team_history(team="Spurs")

File ~/jupyter-env/venv/lib/python3.11/site-packages/soccerdata/clubelo.py:179, in ClubElo.read_team_history(self, team, max_age)
    [176](https://vscode-remote+ssh-002dremote-002b192-002e168-002e1-002e136.vscode-resource.vscode-cdn.net/home/jupyter/jupyter-env/notebooks/~/jupyter-env/venv/lib/python3.11/site-packages/soccerdata/clubelo.py:176)         df.replace({"team": TEAMNAME_REPLACEMENTS}, inplace=True)
    [177](https://vscode-remote+ssh-002dremote-002b192-002e168-002e1-002e136.vscode-resource.vscode-cdn.net/home/jupyter/jupyter-env/notebooks/~/jupyter-env/venv/lib/python3.11/site-packages/soccerdata/clubelo.py:177)         return df
--> [179](https://vscode-remote+ssh-002dremote-002b192-002e168-002e1-002e136.vscode-resource.vscode-cdn.net/home/jupyter/jupyter-env/notebooks/~/jupyter-env/venv/lib/python3.11/site-packages/soccerdata/clubelo.py:179) raise ValueError(f"No data found for team {team}")

ValueError: No data found for team Spurs

Additional context
The same scenario can be also happenning in more dedicated classes, I did not check in depth: Here, here and here
Contributor Action Plan

  • I can fix this issue and will submit a pull request.
  • I’m unsure how to fix this, but I'm willing to work on it with guidance.
  • I’m not able to fix this issue.

This is a trivial change but an important one, I can also fix the tests or make them check the file. Also, I'd suggest we don't use one liners with variables like k and v as those tend to be hard to debug.

Originally created by @MartiONE on GitHub (Sep 12, 2024). Original GitHub issue: https://github.com/probberechts/soccerdata/issues/703 **Describe the bug** The bug appears when you try to call `read_team_history` from ClubElo. The file that contains aliases for team names that might differ from the ClubElo website gets correctly loaded and stored inside the `_config.py` variable `TEAMNAME_REPLACEMENTS`. However, whenever the function `read_team_history` inside the ClubElo class tries to filter the names to process does it in the reverse way, the problematic line is [this one](https://github.com/probberechts/soccerdata/blob/master/soccerdata/clubelo.py#L151) **Affected scrapers** This affects the following scrapers: - [x] ClubElo - [ ] ESPN - [ ] FBref - [ ] FiveThirtyEight - [x] FotMob - [ ] Match History - [x] SoFIFA - [ ] Understat - [ ] WhoScored **Code example** Considering you have a minimal `teamname_replacements.json` like ```{"Tottenham": ["Tottenham Hotspur", "Tottenham Hotspur FC", "Spurs"]}``` and then you run ```python import soccerdata as sd elo = sd.ClubElo() elo.read_team_history(team="Spurs") ``` **Error message** ``` ValueError Traceback (most recent call last) Cell In[4], [line 1](vscode-notebook-cell:?execution_count=4&line=1) ----> [1](vscode-notebook-cell:?execution_count=4&line=1) elo.read_team_history(team="Spurs") File ~/jupyter-env/venv/lib/python3.11/site-packages/soccerdata/clubelo.py:179, in ClubElo.read_team_history(self, team, max_age) [176](https://vscode-remote+ssh-002dremote-002b192-002e168-002e1-002e136.vscode-resource.vscode-cdn.net/home/jupyter/jupyter-env/notebooks/~/jupyter-env/venv/lib/python3.11/site-packages/soccerdata/clubelo.py:176) df.replace({"team": TEAMNAME_REPLACEMENTS}, inplace=True) [177](https://vscode-remote+ssh-002dremote-002b192-002e168-002e1-002e136.vscode-resource.vscode-cdn.net/home/jupyter/jupyter-env/notebooks/~/jupyter-env/venv/lib/python3.11/site-packages/soccerdata/clubelo.py:177) return df --> [179](https://vscode-remote+ssh-002dremote-002b192-002e168-002e1-002e136.vscode-resource.vscode-cdn.net/home/jupyter/jupyter-env/notebooks/~/jupyter-env/venv/lib/python3.11/site-packages/soccerdata/clubelo.py:179) raise ValueError(f"No data found for team {team}") ValueError: No data found for team Spurs ``` **Additional context** The same scenario can be also happenning in more dedicated classes, I did not check in depth: [Here](https://github.com/probberechts/soccerdata/blob/59dfc2f0e5a958f7a2f75f9d88ed6db5ece99b2c/soccerdata/fotmob.py#L372), [here](https://github.com/probberechts/soccerdata/blob/59dfc2f0e5a958f7a2f75f9d88ed6db5ece99b2c/soccerdata/sofifa.py#L247) and [here](https://github.com/probberechts/soccerdata/blob/59dfc2f0e5a958f7a2f75f9d88ed6db5ece99b2c/soccerdata/fbref.py#L418) **Contributor Action Plan** - [x] I can fix this issue and will submit a pull request. - [ ] I’m unsure how to fix this, but I'm willing to work on it with guidance. - [ ] I’m not able to fix this issue. This is a trivial change but an important one, I can also fix the tests or make them check the file. Also, I'd suggest we don't use one liners with variables like `k` and `v` as those tend to be hard to debug.
kerem 2026-03-02 15:56:12 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@MartiONE commented on GitHub (Sep 16, 2024):

Hey @probberechts , am I in the clear to provide a fix for this? :)

<!-- gh-comment-id:2353045093 --> @MartiONE commented on GitHub (Sep 16, 2024): Hey @probberechts , am I in the clear to provide a fix for this? :)
Author
Owner

@probberechts commented on GitHub (Oct 10, 2024):

Great catch! It would be great if you provide a fix.

<!-- gh-comment-id:2405500397 --> @probberechts commented on GitHub (Oct 10, 2024): Great catch! It would be great if you provide a fix.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/soccerdata#148
No description provided.