Skip to content

Commit 4904f03

Browse files
authored
Update pre-commit linting checks (#51)
* 🔧 Update pre-commit config logic * 🔧 Exclude notebooks from ruff checks * 🔧 Add import sorting check to ruff-check * 🚨 Sort imports * 🚚 Move data.anemoi to data_processors * 🚚 Move data.lightning to data_loaders * ♻️ Rename data_processors.ZebraDataset to data_processors.ZebraDataProcessor to avoid duplicated class names * 🔧 Move 'extend-select' into linting section
1 parent 793d9a6 commit 4904f03

27 files changed

Lines changed: 50 additions & 35 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__pycache__
2-
.coverage
2+
.coverage*
33
.DS_Store
44
.ipynb_checkpoints/
55
.python-version

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ repos:
1616
- id: mixed-line-ending
1717
- id: name-tests-test
1818
args: ["--pytest-test-first"]
19-
exclude: ^tests/legacy_metrics.py
2019
- id: trailing-whitespace
2120

2221
- repo: https://github.com/astral-sh/ruff-pre-commit
2322
rev: "v0.12.5"
2423
hooks:
2524
# Run the linter
26-
- id: ruff
27-
types_or: [python, pyi]
25+
- id: ruff-check
2826
args: ["--fix", "--show-fixes"]
27+
pass_filenames: false
2928
# Run the formatter
3029
- id: ruff-format
30+
pass_filenames: false

ice_station_zebra/cli/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import typer
22
from hydra.core.utils import simple_stdout_log_config
33

4-
from ice_station_zebra.data.anemoi import datasets_cli
4+
from ice_station_zebra.data_processors import datasets_cli
55
from ice_station_zebra.evaluation import evaluation_cli
66
from ice_station_zebra.training import training_cli
77

File renamed without changes.

ice_station_zebra/data/lightning/combined_dataset.py renamed to ice_station_zebra/data_loaders/combined_dataset.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
import numpy as np
55
from torch.utils.data import Dataset
66

7-
from .zebra_dataset import ZebraDataset
87
from ice_station_zebra.types import ArrayTCHW
98

9+
from .zebra_dataset import ZebraDataset
10+
1011

1112
class CombinedDataset(Dataset):
1213
def __init__(
File renamed without changes.

ice_station_zebra/data/lightning/zebra_dataset.py renamed to ice_station_zebra/data_loaders/zebra_dataset.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from pathlib import Path
21
from collections.abc import Sequence
2+
from pathlib import Path
33

44
import numpy as np
55
from anemoi.datasets.data import open_dataset
@@ -74,14 +74,14 @@ def __getitem__(self, idx: int) -> ArrayCHW:
7474
"""Return the data for a single timestep in [C, H, W] format"""
7575
return self.dataset[idx].reshape(self.space.chw)
7676

77-
@cachedmethod(lambda self: self._cache)
78-
def index_from_date(self, date: np.datetime64) -> int:
79-
"""Return the index of a given date in the dataset."""
80-
idx, _, _ = self.dataset.to_index(date, 0)
81-
return idx
82-
8377
def get_tchw(self, dates: Sequence[np.datetime64]) -> ArrayTCHW:
8478
"""Return the data for a series of timesteps in [T, C, H, W] format"""
8579
return np.stack(
8680
[self[self.index_from_date(target_date)] for target_date in dates], axis=0
8781
)
82+
83+
@cachedmethod(lambda self: self._cache)
84+
def index_from_date(self, date: np.datetime64) -> int:
85+
"""Return the index of a given date in the dataset."""
86+
idx, _, _ = self.dataset.to_index(date, 0)
87+
return idx
File renamed without changes.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from ice_station_zebra.cli import hydra_adaptor
77

8-
from .zebra_dataset_factory import ZebraDatasetFactory
8+
from .zebra_data_processor_factory import ZebraDataProcessorFactory
99

1010
# Create the typer app
1111
datasets_cli = typer.Typer(help="Manage datasets")
@@ -17,7 +17,7 @@
1717
@hydra_adaptor
1818
def create(config: DictConfig) -> None:
1919
"""Create all datasets"""
20-
factory = ZebraDatasetFactory(config)
20+
factory = ZebraDataProcessorFactory(config)
2121
for dataset in factory.datasets:
2222
log.info(f"Working on {dataset.name}")
2323
dataset.create()
@@ -27,7 +27,7 @@ def create(config: DictConfig) -> None:
2727
@hydra_adaptor
2828
def inspect(config: DictConfig) -> None:
2929
"""Inspect all datasets"""
30-
factory = ZebraDatasetFactory(config)
30+
factory = ZebraDataProcessorFactory(config)
3131
for dataset in factory.datasets:
3232
log.info(f"Working on {dataset.name}")
3333
dataset.inspect()

ice_station_zebra/data/anemoi/preprocessors/__init__.py renamed to ice_station_zebra/data_processors/preprocessors/__init__.py

File renamed without changes.

0 commit comments

Comments
 (0)