Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v1.0.0 #91

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,6 @@ dmypy.json

# Cython debug symbols
cython_debug/

# Mac local files
.DS_Store
30 changes: 12 additions & 18 deletions nfl_data_py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def import_pbp_data(
pbp_data.append(raw)
print(str(year) + ' done.')

except Error as e:
except Exception as e:
print(e)
print('Data not available for ' + str(year))

Expand Down Expand Up @@ -760,7 +760,17 @@ def import_ids(columns=None, ids=None):
raise ValueError('ids variable can only contain ' + ', '.join(avail_sites))

# import data
df = pandas.read_csv(r'https://raw.githubusercontent.com/dynastyprocess/data/master/files/db_playerids.csv')
dtypes = {
'mfl_id': str, 'sportradar_id': str, 'fantasypros_id': str, 'gsis_id': str,
'pff_id': str, 'sleeper_id': str, 'nfl_id': str, 'espn_id': str, 'yahoo_id': str,
'fleaflicker_id': str, 'cbs_id': str, 'pfr_id': str, 'cfbref_id': str,
'rotowire_id': str, 'rotoworld_id': str, 'ktc_id': str, 'stats_id': str,
'stats_global_id': str, 'fantasy_data_id': str, 'swish_id': str, 'name': str,
'merge_name': str, 'position': str, 'team': str, 'age': 'Float64',
'draft_year': 'Int64', 'draft_round': 'Int64', 'draft_pick': 'Int64', 'draft_ovr': 'Int64',
'twitter_username': str, 'height': 'Int64', 'weight': 'Int64', 'college': str, 'db_season': 'Int64'
}
df = pandas.read_csv(r'https://raw.githubusercontent.com/dynastyprocess/data/master/files/db_playerids.csv', dtype=dtypes, parse_dates=['birthdate'])

rem_cols = [x for x in df.columns if x not in avail_ids]
tgt_ids = [x + '_id' for x in ids]
Expand Down Expand Up @@ -1138,18 +1148,6 @@ def clean_nfl_data(df):
'Southern Miss': 'Southern Mississippi',
'Louisiana State': 'LSU'
}

pro_tm_repl = {
'GNB': 'GB',
'KAN': 'KC',
'LA': 'LAR',
'LVR': 'LV',
'NWE': 'NE',
'NOR': 'NO',
'SDG': 'SD',
'SFO': 'SF',
'TAM': 'TB'
}

na_replace = {
'NA':numpy.nan
Expand All @@ -1164,8 +1162,4 @@ def clean_nfl_data(df):
if 'col_team' in df.columns:
df.replace({'col_team': col_tm_repl}, inplace=True)

if 'name' in df.columns:
for z in player_col_tm_repl:
df[df['name'] == z[0]] = df[df['name'] == z[0]].replace({z[1]: z[2]})

return df
14 changes: 6 additions & 8 deletions nfl_data_py/tests/nfl_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest import TestCase
from pathlib import Path
import shutil
import random

import pandas as pd

Expand All @@ -20,7 +21,7 @@ def test_is_df_with_data_thread_requests(self):


def test_uses_cache_when_cache_is_true(self):
cache = Path(__file__).parent/"tmpcache"
cache = Path(__file__).parent/f"tmpcache-{random.randint(0, 10000)}"
self.assertRaises(
ValueError,
nfl.import_pbp_data, [2020], cache=True, alt_path=cache
Expand Down Expand Up @@ -268,17 +269,14 @@ def test_is_df_with_data_thread_requests(self):

class test_cache(TestCase):
def test_cache(self):
cache = Path(__file__).parent/"tmpcache"
cache = Path(__file__).parent/f"tmpcache-{random.randint(0, 10000)}"
self.assertFalse(cache.is_dir())

nfl.cache_pbp([2020], alt_path=cache)

new_paths = list(cache.glob("**/*"))
self.assertEqual(len(new_paths), 2)
self.assertTrue(new_paths[0].is_dir())
self.assertTrue(new_paths[1].is_file())

pbp2020 = pd.read_parquet(new_paths[1])
self.assertTrue(cache.is_dir())

pbp2020 = pd.read_parquet(cache/"season=2020"/"part.0.parquet")
self.assertIsInstance(pbp2020, pd.DataFrame)
self.assertFalse(pbp2020.empty)

Expand Down
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
appdirs
fastparquet
numpy
pandas
13 changes: 7 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@
NAME = 'nfl_data_py'
DESCRIPTION = 'python library for interacting with NFL data sourced from nflfastR'
URL = 'https://github.com/nflverse/nfl_data_py'
EMAIL = 'cooper.dff11@gmail.com'
AUTHOR = 'cooperdff'
REQUIRES_PYTHON = '>=3.6.0'
VERSION = '0.3.2'
EMAIL = 'alec.ostrander@gmail.com'
AUTHOR = 'Alec Ostrander'
REQUIRES_PYTHON = '>=3.9.0'
VERSION = '1.0.0'


# What packages are required for this module to be executed?
REQUIRED = [
'pandas>1',
'pandas>=2',
'numpy=>=2'
'appdirs>1',
'fastparquet>0.5',
]

# What packages are optional?
EXTRAS = {
"fastparquet": ['fastparquet>0.5']
}

# Where the magic happens:
Expand Down
Loading