diff --git a/.flake8 b/.flake8 deleted file mode 100644 index a82cdbcc..00000000 --- a/.flake8 +++ /dev/null @@ -1,5 +0,0 @@ -[flake8] -exclude = __init__.py -extend-ignore = E203, D200 -max-complexity = 10 -max-line-length = 88 diff --git a/constraints.txt b/constraints.txt deleted file mode 100644 index a30d7fa6..00000000 --- a/constraints.txt +++ /dev/null @@ -1,141 +0,0 @@ -aiohttp==3.8.3 -aiosignal==1.3.1 -alabaster==0.7.12 -alembic==1.8.1 -async-timeout==4.0.2 -attrs==22.1.0 -autoflake==1.7.7 -autopage==0.5.1 -Babel==2.11.0 -black==22.10.0 -cachetools==5.2.0 -catboost==1.1 -certifi==2022.9.24 -cfgv==3.3.1 -charset-normalizer==2.1.1 -click==8.1.3 -cliff==4.1.0 -cloudpickle==2.2.0 -cmaes==0.9.0 -cmd2==2.4.2 -colorlog==6.7.0 -contourpy==1.0.6 -coverage==6.5.0 -cramjam==2.6.2 -cycler==0.11.0 -decorator==5.1.1 -distlib==0.3.6 -docker-pycreds==0.4.0 -docutils==0.19 -exceptiongroup==1.0.4 -fastparquet==0.8.3 -filelock==3.8.0 -flake8==5.0.4 -fonttools==4.38.0 -frozenlist==1.3.3 -fsspec==2022.11.0 -gcsfs==2022.11.0 -gitdb==4.0.9 -GitPython==3.1.29 -google-api-core==2.10.2 -google-auth==2.14.1 -google-auth-oauthlib==0.7.1 -google-cloud-core==2.3.2 -google-cloud-storage==2.6.0 -google-crc32c==1.5.0 -google-resumable-media==2.4.0 -googleapis-common-protos==1.57.0 -graphviz==0.20.1 -greenlet==2.0.1 -identify==2.5.9 -idna==3.4 -imagesize==1.4.1 -importlib-metadata==4.13.0 -iniconfig==1.1.1 -isort==5.10.1 -Jinja2==3.1.2 -joblib==1.2.0 -kiwisolver==1.4.4 -llvmlite==0.39.1 -Mako==1.2.4 -MarkupSafe==2.1.1 -matplotlib==3.6.2 -mccabe==0.7.0 -modin==0.17.0 -multidict==6.0.2 -mypy==0.991 -mypy-extensions==0.4.3 -nodeenv==1.7.0 -numba==0.56.4 -numpy==1.23.4 -oauthlib==3.2.2 -optuna==3.0.3 -otc @ file:///Users/XCG1400/git/thesis -packaging==21.3 -pandas==1.5.1 -pathspec==0.10.2 -pathtools==0.1.2 -pbr==5.11.0 -Pillow==9.3.0 -platformdirs==2.5.4 -plotly==5.11.0 -pluggy==1.0.0 -pre-commit==2.20.0 -prettytable==3.5.0 -promise==2.3 -protobuf==4.21.9 -psutil==5.9.4 -psycopg2-binary==2.9.5 -py==1.11.0 -pyasn1==0.4.8 -pyasn1-modules==0.2.8 -pycodestyle==2.9.1 -pydantic==1.10.2 -pyflakes==2.5.0 -Pygments==2.13.0 -pyparsing==3.0.9 -pyperclip==1.8.2 -pytest==7.2.0 -pytest-cov==4.0.0 -python-dateutil==2.8.2 -python-dotenv==0.21.0 -pytz==2022.6 -PyYAML==6.0 -requests==2.28.1 -requests-oauthlib==1.3.1 -rsa==4.9 -scikit-learn==1.1.3 -scipy==1.8.1 -seaborn==0.12.1 -sentry-sdk==1.11.0 -setproctitle==1.3.2 -shap==0.41.0 -shortuuid==1.0.11 -six==1.16.0 -slicer==0.0.7 -smmap==5.0.0 -snowballstemmer==2.2.0 -Sphinx==5.3.0 -sphinxcontrib-applehelp==1.0.2 -sphinxcontrib-devhelp==1.0.2 -sphinxcontrib-htmlhelp==2.0.0 -sphinxcontrib-jsmath==1.0.1 -sphinxcontrib-qthelp==1.0.3 -sphinxcontrib-serializinghtml==1.1.5 -SQLAlchemy==1.4.44 -stevedore==4.1.1 -tenacity==8.1.0 -threadpoolctl==3.1.0 -toml==0.10.2 -tomli==2.0.1 -tox==3.27.1 -tqdm==4.64.1 -typer==0.6.1 -types-PyYAML==6.0.12.2 -typing_extensions==4.4.0 -urllib3==1.26.12 -virtualenv==20.16.7 -wandb==0.13.5 -wcwidth==0.2.5 -yarl==1.8.1 -zipp==3.10.0 diff --git a/pyproject.toml b/pyproject.toml index d17616d4..71914f6b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -90,7 +90,9 @@ select = [ "F", # pyflakes "I", # isort "N", # pep8-naming + "NPY", # numpy "PD", # pandas-vet + "PIE", # misc lints "PT", # pytest "PTH", # flake8-use-pathlib "PGH", # pygrep diff --git a/src/otc/models/objective.py b/src/otc/models/objective.py index fbe40dd8..e22a1e71 100644 --- a/src/otc/models/objective.py +++ b/src/otc/models/objective.py @@ -40,10 +40,6 @@ def set_seed(seed_val: int = 42) -> int: # see https://docs.python.org/3/using/cmdline.html#envvar-PYTHONHASHSEED os.environ["PYTHONHASHSEED"] = str(seed_val) - # pandas and numpy - # https://stackoverflow.com/a/52375474/5755604 - np.random.seed(seed_val) - # python random module random.seed(seed_val) diff --git a/tests/__init__.py b/tests/__init__.py index b58ea23e..67b917ed 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,4 +1 @@ -"""Support for tests. - - -""" +"""Support for tests.""" diff --git a/tests/test_metrics.py b/tests/test_metrics.py index 15606b30..414f3ddd 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -3,7 +3,6 @@ import numpy as np from otc.metrics.metrics import effective_spread -from otc.models.objective import set_seed class TestMetrics: @@ -19,11 +18,10 @@ def test_effective_spread(self) -> None: Value may not be NaN. """ - set_seed(7) - - y_pred = np.random.choice([-1, 1], size=(10)) - trade_price = np.random.rand(10) * 100 - fundamental_value = np.random.rand(10) * 100 + rng = np.random.default_rng(seed=7) + y_pred = rng.choice([-1, 1], size=(10)) + trade_price = rng.random(10) * 100 + fundamental_value = rng.random(10) * 100 e_s = effective_spread(y_pred, trade_price, fundamental_value) diff --git a/tests/test_objective.py b/tests/test_objective.py index 45a8bd5d..1eb32137 100644 --- a/tests/test_objective.py +++ b/tests/test_objective.py @@ -35,7 +35,8 @@ def setup(self) -> None: # make 1 const feature and 1 non-const feature, as catboost requires non-const self._x_train = pd.DataFrame(data={"feature_1": 1}, index=index) - self._x_train["feature_2"] = np.random.randint(1, 6, self._x_train.shape[0]) + rng = np.random.default_rng() + self._x_train["feature_2"] = rng.integers(1, 6, self._x_train.shape[0]) self._y_train = self._x_train["feature_2"] self._x_val = self._x_train.copy() self._y_val = self._y_train.copy() @@ -113,9 +114,9 @@ def test_gradient_boosting_pretraining_objective(self) -> None: # labelled (-1,1) and unlabelled (0) instances # train set with -1, 1, and 0 - self._y_train = pd.Series(np.random.randint(-1, 2, self._y_train.shape[0])) - # val set with 1 rng = np.random.default_rng() + self._y_train = pd.Series(rng.integers(-1, 2, self._y_train.shape[0])) + # val set with 1 self._y_val = rng.integers(low=1, high=2, size=self._y_train.shape[0]) study = optuna.create_study(direction="maximize")