Skip to content

Commit b8d9cd2

Browse files
authored
Merge pull request #721 from DHI/ruff
Ruff format
2 parents a0df19a + 07f8084 commit b8d9cd2

26 files changed

+62
-75
lines changed

.devcontainer/devcontainer.json

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
{
2-
"name": "Python 3",
3-
"image": "mcr.microsoft.com/devcontainers/python:1-3.11-bullseye",
4-
"postCreateCommand": "pip3 install --user -e .'[dev,test,notebooks]'",
5-
"customizations": {
2+
"name": "Python 3",
3+
"image": "mcr.microsoft.com/devcontainers/python:1-3.11-bullseye",
4+
"postCreateCommand": "pip3 install --user -e .'[dev,test,notebooks]'",
5+
"customizations": {
66
"vscode": {
77
"extensions": [
88
"ms-python.python",
99
"ms-toolsai.jupyter",
1010
"GitHub.vscode-pull-request-github",
1111
"charliermarsh.ruff"
12-
1312
],
1413
"settings": {
1514
"editor.formatOnSave": true,
1615
"[python]": {
1716
"editor.formatOnSave": true,
1817
"editor.codeActionsOnSave": {
19-
"source.fixAll": true,
20-
"source.organizeImports": true
18+
"source.fixAll": true,
19+
"source.organizeImports": true
2120
}
22-
},
23-
"python.formatting.provider": "black"
21+
},
22+
"python.formatting.provider": "charliermarsh.ruff",
2423
}
2524
}
2625
}
27-
}
26+
}

.github/workflows/full_test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ jobs:
2323
- uses: actions/checkout@v3
2424
- uses: chartboost/ruff-action@v1 # Fail fast if there are any linting errors
2525
with:
26-
version: 0.5.6 # consistent with pyproject.toml ?
26+
version: 0.6.2 # consistent with pyproject.toml ?
27+
src: mikeio # ignore notebooks
2728
- name: Set up Python ${{ matrix.python-version }}
2829
uses: actions/setup-python@v4
2930
with:

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@
1313
"mypy-type-checker.args": [
1414
"--disallow-untyped-defs",
1515
],
16+
"[python]": {
17+
"editor.formatOnSave": true,
18+
"editor.defaultFormatter": "charliermarsh.ruff"
19+
}
1620
}

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
3. If you are fixing a bug, first add a failing test
66
4. Make changes
77
5. Verify that all tests passes by running `pytest` from the package root directory
8-
6. Format the code by running [black (`pip install black==22.3.0`)](https://black.readthedocs.io/en/stable/) e.g. `black nameofthefiletoformat.py`
8+
6. Format the code by running [`ruff format`](https://docs.astral.sh/ruff/formatter/)
99
6. Make a pull request with a summary of the changes
1010

1111
Tests can also be run with tools like VS Code

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ build: typecheck test
88
python -m build
99

1010
lint:
11-
ruff check .
11+
ruff check mikeio
12+
13+
format:
14+
ruff format $(LIB)/
1215

1316
pylint:
1417
pylint --disable=all --enable=attribute-defined-outside-init mikeio/

mikeio/_track.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def _extract_track(
2828
dtype: Any, # TODO DTypeLike?
2929
data_read_func: Callable[[int, int], Tuple[np.ndarray, float]],
3030
) -> Dataset:
31-
3231
if not isinstance(geometry, GeometryFM2D):
3332
raise NotImplementedError("Only implemented for 2d flexible mesh geometries")
3433

@@ -65,9 +64,7 @@ def _extract_track(
6564
assert isinstance(
6665
times, pd.DatetimeIndex
6766
), "The index must be a pandas.DatetimeIndex"
68-
assert (
69-
times.is_monotonic_increasing
70-
), "The time index must be monotonic increasing. Consider df.sort_index() before passing to extract_track()."
67+
assert times.is_monotonic_increasing, "The time index must be monotonic increasing. Consider df.sort_index() before passing to extract_track()."
7168

7269
data_list = [coords[:, 0], coords[:, 1]] # lon,lat
7370
for item in range(n_items):

mikeio/dataset/_data_plot.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ def __call__(
5959
def _get_ax(
6060
ax: Axes | None = None, figsize: Tuple[float, float] | None = None
6161
) -> Axes:
62-
6362
if ax is None:
6463
_, ax = plt.subplots(figsize=figsize)
6564
return ax
@@ -68,7 +67,6 @@ def _get_ax(
6867
def _get_fig_ax(
6968
ax: Axes | None = None, figsize: Tuple[float, float] | None = None
7069
) -> Tuple[Figure, Axes]:
71-
7270
if ax is None:
7371
fig, ax = plt.subplots(figsize=figsize)
7472
else:

mikeio/dataset/_dataarray.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ def _guess_dims(
220220
ndim_no_time = ndim if (len(dims) == 0) else ndim - 1
221221

222222
if isinstance(geometry, GeometryUndefined):
223-
224223
DIMS_MAPPING: Mapping[int, Sequence[Any]] = {
225224
0: [],
226225
1: ["x"],
@@ -965,7 +964,9 @@ def interp(
965964

966965
if interpolant is None:
967966
interpolant = self.geometry.get_2d_interpolant(
968-
coords, n_nearest=n_nearest, **kwargs # type: ignore
967+
coords, # type: ignore
968+
n_nearest=n_nearest,
969+
**kwargs, # type: ignore
969970
)
970971
dai = self.geometry.interp2d(self, *interpolant).flatten() # type: ignore
971972
if z is None:

mikeio/dataset/_dataset.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,18 @@ def __init__(
9999
):
100100
if not self._is_DataArrays(data):
101101
data = self._create_dataarrays(
102-
data=data, time=time, items=items, geometry=geometry, zn=zn, dims=dims, dt=dt # type: ignore
102+
data=data,
103+
time=time,
104+
items=items,
105+
geometry=geometry,
106+
zn=zn,
107+
dims=dims,
108+
dt=dt,
103109
)
104-
self._data_vars: MutableMapping[str, DataArray] = self._init_from_DataArrays(data, validate=validate) # type: ignore
110+
self._data_vars: MutableMapping[str, DataArray] = self._init_from_DataArrays(
111+
data, # type: ignore
112+
validate=validate,
113+
) # type: ignore
105114
self.plot = _DatasetPlotter(self)
106115

107116
@staticmethod
@@ -124,12 +133,12 @@ def _is_DataArrays(data: Any) -> bool:
124133

125134
@staticmethod
126135
def _create_dataarrays(
127-
data: Sequence[NDArray[np.floating]] | NDArray[np.floating],
136+
data: Any,
128137
time: pd.DatetimeIndex,
129-
items: Sequence[ItemInfo],
138+
items: Any,
130139
geometry: Any,
131-
zn: NDArray[np.floating],
132-
dims: Tuple[str, ...],
140+
zn: Any,
141+
dims: Any,
133142
dt: float,
134143
) -> Mapping[str, DataArray]:
135144
if not isinstance(data, Iterable):
@@ -220,7 +229,7 @@ def _parse_items(
220229

221230
@staticmethod
222231
def _DataArrays_as_mapping(
223-
data: DataArray | Sequence[DataArray] | Mapping[str, DataArray]
232+
data: DataArray | Sequence[DataArray] | Mapping[str, DataArray],
224233
) -> MutableMapping[str, DataArray]:
225234
"""Create dict of DataArrays if necessary"""
226235
if isinstance(data, MutableMapping):
@@ -238,7 +247,7 @@ def _DataArrays_as_mapping(
238247

239248
@staticmethod
240249
def _validate_item_names_and_keys(
241-
data_map: MutableMapping[str, DataArray]
250+
data_map: MutableMapping[str, DataArray],
242251
) -> MutableMapping[str, DataArray]:
243252
for key, da in data_map.items():
244253
if da.name == "NoName":
@@ -489,7 +498,12 @@ def create_data_array(
489498

490499
# TODO: delete this?
491500
@staticmethod
492-
def create_empty_data(n_items: int = 1, n_timesteps: int = 1, n_elements: int | None = None, shape: Tuple[int, ...] | None = None): # type: ignore
501+
def create_empty_data(
502+
n_items: int = 1,
503+
n_timesteps: int = 1,
504+
n_elements: int | None = None,
505+
shape: Tuple[int, ...] | None = None,
506+
) -> list:
493507
data = []
494508
if shape is None:
495509
if n_elements is None:
@@ -948,7 +962,9 @@ def interp(
948962
self.geometry, GeometryFM2D
949963
): # TODO remove this when all geometries implements the same method
950964
interpolant = self.geometry.get_2d_interpolant(
951-
xy, n_nearest=n_nearest, **kwargs # type: ignore
965+
xy, # type: ignore
966+
n_nearest=n_nearest,
967+
**kwargs, # type: ignore
952968
)
953969
das = [da.interp(x=x, y=y, interpolant=interpolant) for da in self]
954970
else:

mikeio/dfs/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
from ._dfs2 import Dfs2
44
from ._dfs3 import Dfs3
55

6-
__all__ = ["Dfs0", "Dfs1", "Dfs2", "Dfs3"]
6+
__all__ = ["Dfs0", "Dfs1", "Dfs2", "Dfs3"]

0 commit comments

Comments
 (0)