From 759eb6ffa653350f492e98c3722918e6402d48b4 Mon Sep 17 00:00:00 2001 From: Ben Dilday Date: Fri, 4 Sep 2020 16:43:11 -0400 Subject: [PATCH] Updates requirements (#50) * installs data before running tests * no install data before tests * removes psycopg2 dependency * updates statcast tests * formatting --- Makefile | 2 +- pybbda/data/sources/fangraphs/_update.py | 6 ++++-- pybbda/data/sources/retrosheet/data.py | 10 ---------- requirements.txt | 1 - .../test_baseball_reference_data.py | 4 ++-- tests/data/test_statcast/test_statcast.py | 8 ++++++-- 6 files changed, 13 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index db7d63b..b92a5a5 100644 --- a/Makefile +++ b/Makefile @@ -60,4 +60,4 @@ install-dev: pip install --quiet -r requirements-dev.txt install: install-dev - pip install -e . \ No newline at end of file + pip install . diff --git a/pybbda/data/sources/fangraphs/_update.py b/pybbda/data/sources/fangraphs/_update.py index 4ef6531..2af5454 100644 --- a/pybbda/data/sources/fangraphs/_update.py +++ b/pybbda/data/sources/fangraphs/_update.py @@ -101,8 +101,10 @@ def _pool_park_factors_update(overwrite=False, season_root=None): overwrite=overwrite, ) else: - logger.info(f"handedness park factors not available for pre-2002 seasons. " - f"skipping {season}") + logger.info( + f"handedness park factors not available for pre-2002 seasons. " + f"skipping {season}" + ) def _pool_do_update(overwrite=False, season_stats=None): diff --git a/pybbda/data/sources/retrosheet/data.py b/pybbda/data/sources/retrosheet/data.py index 637e87c..41929da 100644 --- a/pybbda/data/sources/retrosheet/data.py +++ b/pybbda/data/sources/retrosheet/data.py @@ -1,5 +1,4 @@ import os -import psycopg2 import pandas as pd import logging import glob @@ -36,15 +35,6 @@ def __init__(self, data_root=None): self._engine = None self.chadwick = Chadwick() - def _connect_to_postgres(self, database="retrosheet"): - conn = psycopg2.connect( - database=database, - user=os.environ["PSQL_USER"], - password=os.environ["PSQL_PASS"], - port=os.environ["PSQL_PORT"], - ) - return conn - def create_database(self): if not os.path.exists(self.db_dir): os.makedirs(self.db_dir, exist_ok=True) diff --git a/requirements.txt b/requirements.txt index 8e62d83..411a874 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,6 @@ lxml~=4.5.0 numpy~=1.18.1 pandas~=1.0.4 requests~=2.22.0 -psycopg2~=2.8.4 scipy~=1.4.1 sqlalchemy~=1.3.13 tqdm~=4.46.1 diff --git a/tests/data/test_baseball_reference/test_baseball_reference_data.py b/tests/data/test_baseball_reference/test_baseball_reference_data.py index d3681c9..e0571bb 100644 --- a/tests/data/test_baseball_reference/test_baseball_reference_data.py +++ b/tests/data/test_baseball_reference/test_baseball_reference_data.py @@ -10,13 +10,13 @@ def baseball_ref_data(): def test_war_bat(baseball_ref_data): war_bat = baseball_ref_data.war_bat assert war_bat.year_ID.min() == 1871 - assert war_bat.year_ID.max() == 2019 + assert war_bat.year_ID.max() == 2020 def test_war_pitch(baseball_ref_data): war_pitch = baseball_ref_data.war_pitch assert war_pitch.year_ID.min() == 1871 - assert war_pitch.year_ID.max() == 2019 + assert war_pitch.year_ID.max() == 2020 def test_missing_path(baseball_ref_data): diff --git a/tests/data/test_statcast/test_statcast.py b/tests/data/test_statcast/test_statcast.py index 243441c..de757ef 100644 --- a/tests/data/test_statcast/test_statcast.py +++ b/tests/data/test_statcast/test_statcast.py @@ -34,5 +34,9 @@ def test_statcast_validate_player_type(statcast_data): def test_statcast_batter_data(statcast_data): df = statcast_data.sc_2019_05_01 - mean_ls = df.query('player_name == "Jose Abreu"').loc[:, "launch_speed"].mean() - assert mean_ls == pytest.approx(90.8, 0.01) + mean_ls = ( + df.query('player_name == "Jose Abreu" and description != "foul"') + .loc[:, "launch_speed"] + .mean() + ) + assert mean_ls == pytest.approx(102.05, 0.01)