nflverse / nfl_data_py

Python code for working with NFL play by play data.
MIT License
252 stars 48 forks source link

import_combine_data() breaks with positions and no years param #59

Closed alecglen closed 1 year ago

alecglen commented 1 year ago

There's a bad column reference in the function "positions" instead of "pos". The current tests don't catch it because it's inside a control block that only gets hit when the function is called without a years arg and with a positions arg.

>>> nfl.import_combine_data(positions=["QB"])

Traceback (most recent call last):
  File "/Users/alecostrander/opt/anaconda3/envs/ndp/lib/python3.9/site-packages/pandas/core/indexes/base.py", line 3653, in get_loc
    return self._engine.get_loc(casted_key)
  File "pandas/_libs/index.pyx", line 147, in pandas._libs.index.IndexEngine.get_loc
  File "pandas/_libs/index.pyx", line 176, in pandas._libs.index.IndexEngine.get_loc
  File "pandas/_libs/hashtable_class_helper.pxi", line 7080, in pandas._libs.hashtable.PyObjectHashTable.get_item
  File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'position'

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

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/alecostrander/tutorials/nfl_data_py/nfl_data_py/__init__.py", line 603, in import_combine_data
    df = df[df['position'].isin(positions)]
  File "/Users/alecostrander/opt/anaconda3/envs/ndp/lib/python3.9/site-packages/pandas/core/frame.py", line 3761, in __getitem__
    indexer = self.columns.get_loc(key)
  File "/Users/alecostrander/opt/anaconda3/envs/ndp/lib/python3.9/site-packages/pandas/core/indexes/base.py", line 3655, in get_loc
    raise KeyError(key) from err
KeyError: 'position'