nflverse / nfl_data_py

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

Indexing Issue With import_weekly_rosters #75

Open chrismjim opened 10 months ago

chrismjim commented 10 months ago

When trying to import weekly rosters I keep running into this error:

roster_data = nfl.import_weekly_rosters(years=range(2013, 2024))
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/nfl_data_py/__init__.py", line 474, in import_weekly_rosters
    rosters["age"] = ((roster_dates - rosters.birth_date).dt.days / 365.25).round(3)
    ~~~~~~~^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas/core/frame.py", line 4091, in __setitem__
    self._set_item(key, value)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas/core/frame.py", line 4300, in _set_item
    value, refs = self._sanitize_column(value)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas/core/frame.py", line 5036, in _sanitize_column
    return _reindex_for_setitem(value, self.index)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas/core/frame.py", line 12309, in _reindex_for_setitem
    raise err
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas/core/frame.py", line 12304, in _reindex_for_setitem
    reindexed_value = value.reindex(index)._values
                      ^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas/core/series.py", line 4977, in reindex
    return super().reindex(
           ^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas/core/generic.py", line 5521, in reindex
    return self._reindex_axes(
           ^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas/core/generic.py", line 5544, in _reindex_axes
    new_index, indexer = ax.reindex(
                         ^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 4433, in reindex
    raise ValueError("cannot reindex on an axis with duplicate labels")
ValueError: cannot reindex on an axis with duplicate labels
DylanKeyer commented 7 months ago

+1 - also experiencing this.

Reproducible with:

years = range(2010,2024)
df_rosters = nfl.import_weekly_rosters(years)
scrowder1172 commented 1 month ago

my work around is to get one year at a time.

weekly_rosters = nfl.import_weekly_rosters([2022])