From 499e595d1a62fe870ae9b8a717c1f0cbbd44c2b3 Mon Sep 17 00:00:00 2001 From: cooperdff <87905806+cooperdff@users.noreply.github.com> Date: Sat, 28 Aug 2021 10:22:28 -0500 Subject: [PATCH] fixing cache bug --- nfl_data_py/__init__.py | 23 ++++++++++++++++++----- setup.py | 5 +++-- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/nfl_data_py/__init__.py b/nfl_data_py/__init__.py index 179068a..2a0d81d 100644 --- a/nfl_data_py/__init__.py +++ b/nfl_data_py/__init__.py @@ -4,6 +4,7 @@ import numpy import datetime import appdirs +import os # module level doc string __doc__ = """ @@ -71,17 +72,23 @@ def import_pbp_data(years, columns=None, downcast=True, cache=False, alt_path=No appauthor = 'cooper_dff' plays = pandas.DataFrame() + + if alt_path is None: + dpath = appdirs.user_cache_dir(appname, appauthor) + '\\pbp' + else: + dpath = alt_path # read in pbp data for year in years: + for folder in [dpath + '\\' + x + '\\' for x in os.listdir(dpath) if ('season='+str(year)) in x]: + for file in os.listdir(folder): + if file.endswith(".parquet"): + fpath = os.path.join(folder, file) + # define path based on cache and alt_path variables if cache is True: - if alt_path is None: - alt_path = '' - path = appdirs.user_cache_dir(appname, appauthor) + '\\pbp' - else: - url = alt_path + path = fpath else: path = url1 + str(year) + url2 @@ -146,6 +153,12 @@ def cache_pbp(years, downcast=True, alt_path=None): path = alt_path else: path = appdirs.user_cache_dir(appname, appauthor) + '\\pbp' + + # delete seasons to be replaced + for folder in [path + '\\' + x + '\\' for x in os.listdir(path) for y in years if ('season='+str(y)) in x]: + for file in os.listdir(folder): + if file.endswith(".parquet"): + os.remove(os.path.join(folder, file)) # read in pbp data for year in years: diff --git a/setup.py b/setup.py index 166b64b..dbd2bed 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ EMAIL = 'cooper.dff11@gmail.com' AUTHOR = 'cooperdff' REQUIRES_PYTHON = '>=3.5.0' -VERSION = '0.2.1' +VERSION = '0.2.3' # What packages are required for this module to be executed? @@ -29,7 +29,8 @@ 'fastparquet>0.5', 'python-snappy>0.5', 'snappy>1', - 'appdirs>1' + 'appdirs>1', + 'os' ] # What packages are optional?