Skip to content

Commit

Permalink
add numpy ruff rules
Browse files Browse the repository at this point in the history
  • Loading branch information
KarelZe committed Oct 30, 2023
1 parent 427174b commit c317751
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 163 deletions.
5 changes: 0 additions & 5 deletions .flake8

This file was deleted.

141 changes: 0 additions & 141 deletions constraints.txt

This file was deleted.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions src/otc/models/objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 1 addition & 4 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
"""Support for tests.
"""
"""Support for tests."""
10 changes: 4 additions & 6 deletions tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import numpy as np

from otc.metrics.metrics import effective_spread
from otc.models.objective import set_seed


class TestMetrics:
Expand All @@ -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)

Expand Down
7 changes: 4 additions & 3 deletions tests/test_objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit c317751

Please sign in to comment.