Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix linting issues raised from new pylint and codespell versions #1772

Merged
merged 5 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ values = [

[tool.codespell]
skip = 'xclim/data/*.json,docs/_build,docs/notebooks/xclim_training/*.ipynb,docs/references.bib,__pycache__,*.gz,*.nc,*.png,*.svg,*.whl'
ignore-words-list = "absolue,astroid,bloc,bui,callendar,degreee,environnement,hanel,inferrable,lond,nam,nd,ressources,sie,vas"
ignore-words-list = "absolue,astroid,bloc,bui,callendar,degreee,environnement,hanel,inferrable,lond,nam,nd,ressources,socio-economic,sie,vas"

[tool.coverage.run]
relative_files = true
Expand Down
2 changes: 2 additions & 0 deletions tests/test_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def test_time_bnds_irregular(typ):
elif typ == "pd":
start = pd.date_range("1990-01-01", periods=24, freq="MS")
end = pd.date_range("1990-01-01 23:59:59.999999999", periods=24, freq="ME")
else:
raise ValueError("`typ` must be 'pd' or 'xr'")

time = start + (end - start) / 2

Expand Down
2 changes: 2 additions & 0 deletions tests/test_indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -2971,6 +2971,8 @@ def test_rain_season(pr_series, result_type, method_dry_start):
elif result_type == "end_cond_fails":
pr[{"time": 99 + 20 - 1}] = 5
out_exp = [3, np.NaN, 363]
else:
raise ValueError(f"Unknown result_type: {result_type}")

out = {}
out["start"], out["end"], out["length"] = xci.rain_season(
Expand Down
8 changes: 8 additions & 0 deletions xclim/indices/fire/_cffwis.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,8 @@ def _fire_season(
elif method in ["LA08", "GFWED"]:
# In LA08, the check INCLUDES the current day,
start_index = max(temp_condition_days, snow_condition_days)
else:
raise ValueError("`method` must be one of 'WF93', 'LA08' or 'GFWED'.")

for it in range(start_index, tas.shape[-1]):
if method == "WF93":
Expand Down Expand Up @@ -627,6 +629,8 @@ def _fire_season(

# Shut down when mean snow OR mean temp are over/under threshold
shut_down = (msnow >= snow_thresh) | (mtemp < temp_end_thresh)
else:
raise ValueError("`method` must be one of 'WF93', 'LA08' or 'GFWED'.")

# Mask is on if the previous days was on OR is there is a start-up, AND if it's not a shut-down,
# Aka is off if either the previous day was or it is a shut-down.
Expand Down Expand Up @@ -687,6 +691,10 @@ def _fire_weather_calc( # noqa: C901

overwintering = params["overwintering"]
dry_start = params["dry_start"]

ow_DC = dc0.copy() if dc0 is not None else None
ow_DMC = dmc0.copy() if dmc0 is not None else None

if overwintering and "DC" in ind_prevs:
# In overwintering, dc0 is understood as the previous season's last DC code.
ow_DC = dc0.copy()
Expand Down
2 changes: 1 addition & 1 deletion xclim/indices/fire/_ffdi.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def _griffiths_drought_factor(p, smd, lim, df): # pragma: no cover
# N = 0 defines a rainfall event since 9am today,
# so doesn't apply here, where p is the rainfall
# over previous 24 hours.
x_ = N**1.3 / (N**1.3 + P - 2.0)
x_ = N**1.3 / (N**1.3 + P - 2.0) # pylint: disable=E0601
x = min(x_, x)

conseq = 0
Expand Down
6 changes: 5 additions & 1 deletion xclim/sdba/adjustment.py
Original file line number Diff line number Diff line change
Expand Up @@ -959,14 +959,18 @@ def _compute_transform_matrix(reference, historical):
# This step needs vectorize with dask, but vectorize doesn't work with dask, argh.
# Invert to get transformation matrix from hist to PC coords.
Hinv = np.linalg.inv(H)
# Fancy tricks to choose best orientation on each axes
# Fancy tricks to choose the best orientation on each axis.
# (using eigenvectors, the output axes orientation is undefined)
if best_orientation == "simple":
orient = best_pc_orientation_simple(R, Hinv)
elif best_orientation == "full":
orient = best_pc_orientation_full(
R, Hinv, reference.mean(axis=1), historical.mean(axis=1), historical
)
else:
raise ValueError(
f"Unknown `best_orientation` method: {best_orientation}."
)
# Get transformation matrix
return (R * orient) @ Hinv

Expand Down
21 changes: 11 additions & 10 deletions xclim/sdba/loess.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,21 @@ def _loess_nb(
Parameters
----------
x : np.ndarray
X-coordinates of the points.
X-coordinates of the points.
y : np.ndarray
Y-coordinates of the points.
Y-coordinates of the points.
f : float
Parameter controlling the shape of the weight curve. Behavior depends on the weighting function.
Parameter controlling the shape of the weight curve. Behavior depends on the weighting function.
niter : int
Number of robustness iterations to execute.
Number of robustness iterations to execute.
weight_func : numba func
Numba function giving the weights when passed abs(x - xi) / hi
Numba function giving the weights when passed abs(x - xi) / hi
dx : float
The spacing of the x coordinates. If above 0, this enables the optimization for equally spaced x coordinates.
Must be 0 if spacing is unequal (default).
The spacing of the x coordinates. If above 0, this enables the optimization for equally spaced x coordinates.
Must be 0 if spacing is unequal (default).
skipna : bool
If True (default), remove NaN values before computing the loess. The output has the
same missing values as the input.
If True (default), remove NaN values before computing the loess. The output has the
same missing values as the input.

References
----------
Expand Down Expand Up @@ -150,7 +150,8 @@ def _loess_nb(
else:
h = (hw + 1) * dx
wi = weight_func(diffs / h)
w = di * wi
# Is it expected that `wi` always be assigned before first being called?
w = di * wi # pylint: disable=E0606
else:
# The weights computation is repeated niter times
# The distance of points from the current centre point.
Expand Down
15 changes: 8 additions & 7 deletions xclim/sdba/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import types
from collections.abc import Sequence
from typing import cast

import dask.array as dsk
import numpy as np
Expand Down Expand Up @@ -584,14 +585,12 @@ def to_additive_space(
float
)

from typing import cast

with xr.set_options(keep_attrs=True), np.errstate(divide="ignore"):
if trans == "log":
out = cast(xr.DataArray, np.log(data - lower_bound_array))
elif trans == "logit":
elif trans == "logit" and upper_bound is not None:
data_prime = (data - lower_bound_array) / (
upper_bound_array - lower_bound_array
upper_bound_array - lower_bound_array # pylint: disable=E0606
)
out = cast(xr.DataArray, np.log(data_prime / (1 - data_prime)))
else:
Expand Down Expand Up @@ -684,7 +683,7 @@ def from_additive_space(
lower_bound_array = np.array(data.attrs["sdba_transform_lower"]).astype(
float
)
if trans == "logit":
if trans == "logit" and upper_bound is not None:
upper_bound_array = np.array(data.attrs["sdba_transform_upper"]).astype(
float
)
Expand Down Expand Up @@ -714,10 +713,12 @@ def from_additive_space(
with xr.set_options(keep_attrs=True):
if trans == "log":
out = np.exp(data) + lower_bound_array
elif trans == "logit":
elif trans == "logit" and upper_bound is not None:
out_prime = 1 / (1 + np.exp(-data))
out = (
out_prime * (upper_bound_array - lower_bound_array) + lower_bound_array
out_prime
* (upper_bound_array - lower_bound_array) # pylint: disable=E0606
+ lower_bound_array
)
else:
raise NotImplementedError("`trans` must be one of 'log' or 'logit'.")
Expand Down
Loading