Skip to content

Commit 11d50e3

Browse files
authored
Merge pull request #445 from DHI/ruff
Use ruff for formatting instead of black
2 parents c6e0890 + 0f534e1 commit 11d50e3

File tree

17 files changed

+37
-29
lines changed

17 files changed

+37
-29
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"source.organizeImports": true
2121
}
2222
},
23-
"python.formatting.provider": "black"
23+
"python.formatting.provider": "charliermarsh.ruff",
2424
}
2525
}
2626
}

.github/workflows/full_test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
- uses: actions/checkout@v3
2222
- uses: chartboost/ruff-action@v1 # Fail fast if there are any linting errors
2323
with:
24+
version: 0.6.2
2425
src: "modelskill"
2526
- name: Set up Python ${{ matrix.python-version }}
2627
uses: actions/setup-python@v4

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"[python]": {
3-
"editor.defaultFormatter": "ms-python.black-formatter",
3+
"editor.defaultFormatter": "charliermarsh.ruff",
44
"editor.formatOnSave": true
55
},
66
"python.testing.pytestArgs": [

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
2. Install package in editable mode `pip install -e .[dev]`, including development dependencies
55
3. Make changes
66
4. Verify that all tests passes by running `pytest` from the package root directory
7-
5. Format the code by running [black](https://black.readthedocs.io/en/stable/) e.g. `black nameofthefiletoformat.py`
7+
5. Format the code by running [`ruff format`](https://docs.astral.sh/ruff/formatter/)
88
6. Make a pull request with a summary of the changes

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ build: typecheck test
88
lint:
99
ruff check $(LIB)
1010

11+
format:
12+
ruff format $(LIB)
13+
1114
test:
1215
pytest --disable-warnings
1316

modelskill/comparison/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
"""The `comparison` module contains different types of classes for single
1+
"""The `comparison` module contains different types of classes for single
22
observation comparison (Comparer), and collections of Comparers (ComparerCollection).
33
"""
4+
45
from ._comparison import Comparer
56
from ._collection import ComparerCollection
67

modelskill/comparison/_comparison.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ def _validate_metrics(metrics: Iterable[Any]) -> None:
233233
@dataclass
234234
class ItemSelection:
235235
"Utility class to keep track of observation, model and auxiliary items"
236+
236237
obs: str
237238
model: Sequence[str]
238239
aux: Sequence[str]
@@ -793,7 +794,8 @@ def __iadd__(self, other: Comparer): # type: ignore
793794
else:
794795
self.raw_mod_data.update(other.raw_mod_data)
795796
matched = match_space_time(
796-
observation=self._to_observation(), raw_mod_data=self.raw_mod_data # type: ignore
797+
observation=self._to_observation(),
798+
raw_mod_data=self.raw_mod_data, # type: ignore
797799
)
798800
self.data = matched
799801

@@ -821,7 +823,8 @@ def __add__(
821823
raw_mod_data = self.raw_mod_data.copy()
822824
raw_mod_data.update(other.raw_mod_data) # TODO!
823825
matched = match_space_time(
824-
observation=self._to_observation(), raw_mod_data=raw_mod_data # type: ignore
826+
observation=self._to_observation(),
827+
raw_mod_data=raw_mod_data, # type: ignore
825828
)
826829
cmp = Comparer(matched_data=matched, raw_mod_data=raw_mod_data)
827830

@@ -879,7 +882,9 @@ def sel(
879882
d = d.sel(time=d.time.to_index().to_frame().loc[start:end].index) # type: ignore
880883

881884
# Note: if user asks for a specific time, we also filter raw
882-
raw_mod_data = {k: v.sel(time=slice(start, end)) for k, v in raw_mod_data.items()} # type: ignore
885+
raw_mod_data = {
886+
k: v.sel(time=slice(start, end)) for k, v in raw_mod_data.items()
887+
} # type: ignore
883888
if time is not None:
884889
d = d.sel(time=time)
885890

modelskill/matching.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,9 @@ def match(
258258
if isinstance(obs, Collection):
259259
assert all(isinstance(o, get_args(ObsInputType)) for o in obs)
260260
else:
261-
raise TypeError(f"Obs is not the correct type: it is {type(obs)}. Check the order of the arguments (obs, mod).")
261+
raise TypeError(
262+
f"Obs is not the correct type: it is {type(obs)}. Check the order of the arguments (obs, mod)."
263+
)
262264

263265
if len(obs) > 1 and isinstance(mod, Collection) and len(mod) > 1:
264266
if not all(isinstance(m, (DfsuModelResult, GridModelResult)) for m in mod):

modelskill/metrics.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
"""The `metrics` module contains different skill metrics for evaluating the
2-
difference between a model and an observation.
1+
"""The `metrics` module contains different skill metrics for evaluating the
2+
difference between a model and an observation.
33
44
* [bias][modelskill.metrics.bias]
55
* [max_error][modelskill.metrics.max_error]
6-
* [root_mean_squared_error (rmse)][modelskill.metrics.root_mean_squared_error]
6+
* [root_mean_squared_error (rmse)][modelskill.metrics.root_mean_squared_error]
77
* [urmse][modelskill.metrics.urmse]
88
* [mean_absolute_error (mae)][modelskill.metrics.mean_absolute_error]
99
* [mean_absolute_percentage_error (mape)][modelskill.metrics.mean_absolute_percentage_error]

modelskill/model/_base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ def _extract_track(
8989

9090

9191
class Alignable(Protocol):
92-
9392
@property
9493
def time(self) -> pd.DatetimeIndex: ...
9594

0 commit comments

Comments
 (0)