statsbomb/statsbombpy

Key Issue Error on attempt to retrieve data

Closed this issue · 3 comments

Contact Details

Clever66048@gmail.com

Version

1.0.1

What platform are you seeing the problem on?

Windows

What Python version are you running, are you using a virtual environment? Give us as much info as you can.

Python 3.7 - on Kaggle and on my local PC

What happened?

When I try to retrieve data, for example with statsbombpy.competitions(), I get KeyValue error. To be more precise:
statsbombpy.competitions() - "KeyError: 'competition_gender'"
statsbombpy.matches(competition_id=37, season_id=90) - "KeyError: 'metadata'"

It was working perfectly yesterday.

Reproduced both on Kaggle and on my local PC.

Note: I don't specify anu credential and try to access only open data.

Relevant log output

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/opt/conda/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   3360             try:
-> 3361                 return self._engine.get_loc(casted_key)
   3362             except KeyError as err:

/opt/conda/lib/python3.7/site-packages/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

/opt/conda/lib/python3.7/site-packages/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'metadata'

The above exception was the direct cause of the following exception:

KeyError                                  Traceback (most recent call last)
/tmp/ipykernel_27/3270399515.py in <module>
----> 1 f_eng_matches = sb.matches(competition_id=37, season_id=90)
      2 f_eng_matches.head(2)

/opt/conda/lib/python3.7/site-packages/statsbombpy/sb.py in matches(competition_id, season_id, fmt, creds)
     67         matches["home_managers"] = home_managers
     68         matches["away_managers"] = away_managers
---> 69         metadata = matches.pop("metadata")
     70         for k in ["data_version", "shot_fidelity_version", "xy_fidelity_version"]:
     71             matches[k] = metadata.apply(lambda x: x.get(k))

/opt/conda/lib/python3.7/site-packages/pandas/core/frame.py in pop(self, item)
   5224         3  monkey        NaN
   5225         """
-> 5226         return super().pop(item=item)
   5227 
   5228     @doc(NDFrame.replace, **_shared_doc_kwargs)

/opt/conda/lib/python3.7/site-packages/pandas/core/generic.py in pop(self, item)
    868 
    869     def pop(self, item: Hashable) -> Series | Any:
--> 870         result = self[item]
    871         del self[item]
    872 

/opt/conda/lib/python3.7/site-packages/pandas/core/frame.py in __getitem__(self, key)
   3456             if self.columns.nlevels > 1:
   3457                 return self._getitem_multilevel(key)
-> 3458             indexer = self.columns.get_loc(key)
   3459             if is_integer(indexer):
   3460                 indexer = [indexer]

/opt/conda/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   3361                 return self._engine.get_loc(casted_key)
   3362             except KeyError as err:
-> 3363                 raise KeyError(key) from err
   3364 
   3365         if is_scalar(key) and isna(key) and not self.hasnans:

KeyError: 'metadata'

Code to reproduce issue

from statsbombpy import sb

competitions = sb.competitions().sort_values('season_name', ascending=False)

f_eng_matches = sb.matches(competition_id=37, season_id=90)

Attempted solutions

I checked whether a new input paratameter is required, but couldn't find any information on that

UPDATE: As far as I understand, the problem is that format of statsbomb/open-data has changed with the latest update. For example, competiotions.json doesn't have competition_gender feature anymore

Thanks for flagging this. This should be fixed now. Sorry for the inconvenience.

Thank you very much. Everything works now