Skip to content

Commit

Permalink
lint: automatically fix RUF fixable errors
Browse files Browse the repository at this point in the history
To reproduce the changes:
```
ruff check --fix black_it tests examples scripts
make black
```
  • Loading branch information
marcofavorito authored and marcofavoritobi committed Sep 1, 2023
1 parent 83e7edb commit 35ca6c5
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion black_it/loss_functions/gsl_div.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def compute_loss_1d(

return gsl_loss / ensemble_size

def gsl_div_1d_1_sample( # noqa: PLR0913
def gsl_div_1d_1_sample(
self,
sim_xd: NDArray,
obs_xd: NDArray,
Expand Down
2 changes: 1 addition & 1 deletion black_it/loss_functions/msm.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __str__(self) -> str:
class MethodOfMomentsLoss(BaseLoss):
"""Class for the 'method of moments' loss."""

def __init__( # noqa: PLR0913
def __init__(
self,
covariance_mat: str | NDArray[np.float64] = "identity",
coordinate_weights: NDArray[np.float64] | None = None,
Expand Down
2 changes: 1 addition & 1 deletion black_it/plot/plot_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def plot_convergence(saving_folder: str | os.PathLike) -> None:
sampler_names = _get_samplers_names(saving_folder, ids)

handles, labels = g.get_legend_handles_labels()
labels = sampler_names + [labels[-1]]
labels = [*sampler_names, labels[-1]]

plt.legend(handles, labels, loc="upper right")

Expand Down
2 changes: 1 addition & 1 deletion black_it/schedulers/rl/agents/epsilon_greedy.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
class MABEpsilonGreedy(Agent[int, int]):
"""Implementation of a MAB eps-greedy algorithm."""

def __init__( # noqa: PLR0913
def __init__(
self,
n_actions: int,
alpha: float,
Expand Down
2 changes: 1 addition & 1 deletion examples/models/economics/boltzmann_wealth.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,5 @@ def compute_gini(model: BoltzmannWealthModel) -> float:
agent_wealths = [cast(MoneyAgent, agent).wealth for agent in model.schedule.agents]
x = sorted(agent_wealths)
n = model.num_agents
b = sum(xi * (n - i) for i, xi in enumerate(x)) / (n * sum(x)) # noqa: N806
b = sum(xi * (n - i) for i, xi in enumerate(x)) / (n * sum(x))
return 1 + (1 / n) - 2 * b
12 changes: 8 additions & 4 deletions examples/models/sir/simlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,18 @@ def _build_simulator_cmdline(
Returns:
the arguments for the Docker CLI
"""
return ["docker", "run", "--rm", docker_image_name] + list(
chain.from_iterable(
(
return [
"docker",
"run",
"--rm",
docker_image_name,
*list(
chain.from_iterable(
(f"--{argname}", str(argvalue))
for argname, argvalue in sim_params.items()
),
),
)
]


def execute_simulator(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_examples/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_run(self) -> None:

assert (
process_output.returncode == 0
), f"{str(self.script_path)} exited with error code {process_output.returncode}"
), f"{self.script_path!s} exited with error code {process_output.returncode}"

assert all(
line in process_output.stdout for line in self.expected_lines
Expand Down
2 changes: 1 addition & 1 deletion tests/test_examples/test_sir_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from examples.models.sir.sir_python import SIR, SIR_w_breaks
except ModuleNotFoundError as e:
pytest.skip(
f"skipping tests for SIR python models, reason: {str(e)}",
f"skipping tests for SIR python models, reason: {e!s}",
allow_module_level=True,
)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_plot/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ class BasePlotResultsTest(BasePlotTest):
@classmethod
def setup(cls) -> None:
"""Set up the test."""
cls.args = [cls.saving_folder] + cls.args
cls.args = [cls.saving_folder, *cls.args]

0 comments on commit 35ca6c5

Please sign in to comment.