Skip to content

Commit

Permalink
Replace pre-commit in the CI (#1666)
Browse files Browse the repository at this point in the history
* Replace pre-commit in CI with explicit checks

* Ignore the remaining MyPy typing errors
  • Loading branch information
e10e3 authored Feb 24, 2025
1 parent 19e72e9 commit 7afeaa5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,11 @@ jobs:
python-version: "3.13"
build-root: false

- name: Run pre-commit on all files
run: poetry run pre-commit run --all-files
- name: MyPy type check
run: poetry run mypy

- name: Ruff code linting
run: poetry run ruff check --output-format=github river/

- name: Ruff code formatting
run: poetry run ruff format --check river/
4 changes: 2 additions & 2 deletions river/anomaly/pad.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ def learn_one(self, x: dict | None, y: base.typing.Target | float):
else:
self.predictive_model.learn_one(y=y, x=x)
else:
self.predictive_model.learn_one(x=x, y=y)
self.predictive_model.learn_one(x=x, y=y) # type: ignore[union-attr]

def score_one(self, x: dict, y: base.typing.Target):
# Return the predicted value of x from the predictive model, first by checking whether
# it is a time-series forecaster.
if isinstance(self.predictive_model, time_series.base.Forecaster):
y_pred = self.predictive_model.forecast(self.horizon)[0]
else:
y_pred = self.predictive_model.predict_one(x)
y_pred = self.predictive_model.predict_one(x) # type: ignore[union-attr]

# Calculate the squared error
squared_error = (y_pred - y) ** 2
Expand Down
2 changes: 1 addition & 1 deletion river/preprocessing/scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def transform_many(self, X: pd.DataFrame):
# Check if the dtype is integer type and convert to corresponding float type
if np.issubdtype(dtype, np.integer):
bytes_size = dtype.itemsize
dtype = np.dtype(f"float{bytes_size * 8}")
dtype = np.dtype(f"float{bytes_size * 8}") # type: ignore[operator]

means = np.array([self.means[c] for c in X.columns], dtype=dtype)
Xt = X.values - means
Expand Down
8 changes: 4 additions & 4 deletions river/stream/qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ def simulate_qa(

mementos: list[Memento] = []

kwargs: list
kwargs_list: list

for i, (x, y, *kwargs) in enumerate(dataset):
kwargs = kwargs[0] if kwargs else None
for i, (x, y, *kwargs_list) in enumerate(dataset):
kwargs = kwargs_list[0] if kwargs_list else None

t = get_moment(i, x)
d = get_delay(x, y) # type: ignore
Expand All @@ -168,7 +168,7 @@ def simulate_qa(
)
del mementos[0]

queue(mementos, Memento(i, x, y, kwargs, t + d))
queue(mementos, Memento(i, x, y, kwargs, t + d)) # type: ignore[operator]
if copy:
x = deepcopy(x)
yield (i, x, None, kwargs) if kwargs else (i, x, None)
Expand Down

0 comments on commit 7afeaa5

Please sign in to comment.