Skip to content

Commit 72d9960

Browse files
authored
Update pre-commit hooks (#228)
1 parent c3ececf commit 72d9960

21 files changed

+442
-392
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,4 @@ target/
6565

6666
# tests
6767
.pytest_cache/*
68+
.mypy_cache/

.pre-commit-config.yaml

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,20 @@ repos:
1313
exclude: "asv_bench/asv.conf.json"
1414
- id: check-yaml
1515

16-
- repo: https://github.com/psf/black
17-
rev: 24.4.2
16+
- repo: https://github.com/astral-sh/ruff-pre-commit
17+
rev: "v0.5.5"
1818
hooks:
19-
- id: black-jupyter
20-
21-
- repo: https://github.com/PyCQA/flake8
22-
rev: 7.1.0
23-
hooks:
24-
- id: flake8
25-
- repo: https://github.com/asottile/seed-isort-config
26-
rev: v2.2.0
27-
hooks:
28-
- id: seed-isort-config
29-
- repo: https://github.com/PyCQA/isort
30-
rev: 5.13.2
31-
hooks:
32-
- id: isort
19+
- id: ruff
20+
args: ["--fix"]
21+
- id: ruff-format
3322

3423
- repo: https://github.com/pre-commit/mirrors-prettier
3524
rev: v4.0.0-alpha.8
3625
hooks:
3726
- id: prettier
3827

3928
- repo: https://github.com/pre-commit/mirrors-mypy
40-
rev: v1.10.1
29+
rev: v1.11.0
4130
hooks:
4231
- id: mypy
4332
additional_dependencies: [

asv_bench/benchmarks/accessors.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ class Accessor:
1717
def setup(self, *args, **kwargs):
1818
self.ds = xr.Dataset(
1919
{
20-
"var1": (("x", "y", "t"), randn_xyt),
20+
'var1': (('x', 'y', 't'), randn_xyt),
2121
},
2222
coords={
23-
"x": np.arange(nx),
24-
"y": np.linspace(0, 1, ny),
25-
"t": pd.date_range("1970-01-01", periods=nt, freq="D"),
23+
'x': np.arange(nx),
24+
'y': np.linspace(0, 1, ny),
25+
't': pd.date_range('1970-01-01', periods=nt, freq='D'),
2626
},
2727
)
2828

2929
@parameterized(
30-
["input_dims"],
31-
([{"x": 10}, {"x": 10, "y": 5}, {"x": 10, "y": 5, "t": 2}],),
30+
['input_dims'],
31+
([{'x': 10}, {'x': 10, 'y': 5}, {'x': 10, 'y': 5, 't': 2}],),
3232
)
3333
def time_input_dims(self, input_dims):
3434
"""

asv_bench/benchmarks/batches.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ class Base:
1717
def setup(self):
1818
self.ds = xr.Dataset(
1919
{
20-
"var1": (("x", "y", "t"), randn_xyt),
20+
'var1': (('x', 'y', 't'), randn_xyt),
2121
},
2222
coords={
23-
"x": np.arange(nx),
24-
"y": np.linspace(0, 1, ny),
25-
"t": pd.date_range("1970-01-01", periods=nt, freq="D"),
23+
'x': np.arange(nx),
24+
'y': np.linspace(0, 1, ny),
25+
't': pd.date_range('1970-01-01', periods=nt, freq='D'),
2626
},
2727
)
2828

@@ -34,8 +34,8 @@ class NoPreload(Base):
3434

3535
def setup(self):
3636
super().setup()
37-
ds_dask = self.ds.chunk({"t": 2})
38-
self.bg = BatchGenerator(ds_dask, input_dims={"t": 2}, preload_batch=False)
37+
ds_dask = self.ds.chunk({'t': 2})
38+
self.bg = BatchGenerator(ds_dask, input_dims={'t': 2}, preload_batch=False)
3939

4040
def time_next_batch(self):
4141
"""
@@ -51,7 +51,7 @@ class OneInputDim(Base):
5151

5252
def setup(self):
5353
super().setup()
54-
self.bg = BatchGenerator(self.ds, input_dims={"x": 10})
54+
self.bg = BatchGenerator(self.ds, input_dims={'x': 10})
5555

5656
def time_next_batch(self):
5757
"""
@@ -67,7 +67,7 @@ class AllInputDim(Base):
6767

6868
def setup(self):
6969
super().setup()
70-
self.bg = BatchGenerator(self.ds, input_dims={"x": 10, "y": 10, "t": 5})
70+
self.bg = BatchGenerator(self.ds, input_dims={'x': 10, 'y': 10, 't': 5})
7171

7272
def time_next_batch(self):
7373
"""
@@ -84,7 +84,7 @@ class InputDimInputOverlap(Base):
8484
def setup(self):
8585
super().setup()
8686
self.bg = BatchGenerator(
87-
self.ds, input_dims={"x": 10, "y": 10}, input_overlap={"x": 5, "y": 5}
87+
self.ds, input_dims={'x': 10, 'y': 10}, input_overlap={'x': 5, 'y': 5}
8888
)
8989

9090
def time_next_batch(self):
@@ -102,7 +102,7 @@ class InputDimConcat(Base):
102102
def setup(self):
103103
super().setup()
104104
self.bg = BatchGenerator(
105-
self.ds, input_dims={"x": 10, "y": 10}, concat_input_dims=True
105+
self.ds, input_dims={'x': 10, 'y': 10}, concat_input_dims=True
106106
)
107107

108108
def time_next_batch(self):
@@ -120,7 +120,7 @@ class InputDimBatchDim(Base):
120120
def setup(self):
121121
super().setup()
122122
self.bg = BatchGenerator(
123-
self.ds, input_dims={"x": 10, "y": 10}, batch_dims={"t": 2}
123+
self.ds, input_dims={'x': 10, 'y': 10}, batch_dims={'t': 2}
124124
)
125125

126126
def time_next_batch(self):
@@ -139,8 +139,8 @@ def setup(self):
139139
super().setup()
140140
self.bg = BatchGenerator(
141141
self.ds,
142-
input_dims={"x": 5, "y": 5},
143-
batch_dims={"x": 10, "y": 10},
142+
input_dims={'x': 5, 'y': 5},
143+
batch_dims={'x': 10, 'y': 10},
144144
concat_input_dims=True,
145145
)
146146

@@ -160,8 +160,8 @@ def setup(self):
160160
super().setup()
161161
self.bg = BatchGenerator(
162162
self.ds,
163-
input_dims={"x": 10, "y": 10},
164-
input_overlap={"x": 5, "y": 5},
163+
input_dims={'x': 10, 'y': 10},
164+
input_overlap={'x': 5, 'y': 5},
165165
concat_input_dims=True,
166166
)
167167

asv_bench/benchmarks/generators.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,27 @@ class Generator:
1717
def setup(self, *args, **kwargs):
1818
self.ds = xr.Dataset(
1919
{
20-
"var1": (("x", "y", "t"), randn_xyt),
20+
'var1': (('x', 'y', 't'), randn_xyt),
2121
},
2222
coords={
23-
"x": np.arange(nx),
24-
"y": np.linspace(0, 1, ny),
25-
"t": pd.date_range("1970-01-01", periods=nt, freq="D"),
23+
'x': np.arange(nx),
24+
'y': np.linspace(0, 1, ny),
25+
't': pd.date_range('1970-01-01', periods=nt, freq='D'),
2626
},
2727
)
2828

29-
@parameterized(["preload_batch"], ([True, False]))
29+
@parameterized(['preload_batch'], ([True, False]))
3030
def time_batch_preload(self, preload_batch):
3131
"""
3232
Construct a generator on a chunked DataSet with and without preloading
3333
batches.
3434
"""
35-
ds_dask = self.ds.chunk({"t": 2})
36-
BatchGenerator(ds_dask, input_dims={"t": 2}, preload_batch=preload_batch)
35+
ds_dask = self.ds.chunk({'t': 2})
36+
BatchGenerator(ds_dask, input_dims={'t': 2}, preload_batch=preload_batch)
3737

3838
@parameterized(
39-
["input_dims"],
40-
([{"x": 10}, {"x": 10, "y": 5}, {"x": 10, "y": 5, "t": 2}],),
39+
['input_dims'],
40+
([{'x': 10}, {'x': 10, 'y': 5}, {'x': 10, 'y': 5, 't': 2}],),
4141
)
4242
def time_input_dims(self, input_dims):
4343
"""
@@ -53,30 +53,30 @@ def time_input_dims_and_input_overlap(self):
5353
Benchmark simple batch generation case.
5454
"""
5555
BatchGenerator(
56-
self.ds, input_dims={"x": 10, "y": 10}, input_overlap={"x": 5, "y": 5}
56+
self.ds, input_dims={'x': 10, 'y': 10}, input_overlap={'x': 5, 'y': 5}
5757
)
5858

59-
@parameterized(["concat_input_dims"], (["True", "False"]))
59+
@parameterized(['concat_input_dims'], (['True', 'False']))
6060
def time_input_dims_and_concat_input_dims(self, concat_input_dims):
6161
"""
6262
Benchmark concat_input_dims
6363
"""
6464
BatchGenerator(
65-
self.ds, input_dims={"x": 10, "y": 5}, concat_input_dims=concat_input_dims
65+
self.ds, input_dims={'x': 10, 'y': 5}, concat_input_dims=concat_input_dims
6666
)
6767

6868
@parameterized(
69-
["input_dims", "batch_dims"],
70-
([{"x": 10}, {"x": 10, "y": 5}],),
69+
['input_dims', 'batch_dims'],
70+
([{'x': 10}, {'x': 10, 'y': 5}],),
7171
)
7272
def time_input_dims_and_batch_dims(self, input_dims):
7373
"""
7474
Benchmark batch generator with input_dims and batch_dims.
7575
"""
76-
BatchGenerator(self.ds, input_dims=input_dims, batch_dims={"t": 2})
76+
BatchGenerator(self.ds, input_dims=input_dims, batch_dims={'t': 2})
7777

7878
@parameterized(
79-
["concat_input_dims"],
79+
['concat_input_dims'],
8080
([True, False]),
8181
)
8282
def time_input_dims_batch_dims_and_concat_input_dims(self, concat_input_dims):
@@ -86,13 +86,13 @@ def time_input_dims_batch_dims_and_concat_input_dims(self, concat_input_dims):
8686
"""
8787
BatchGenerator(
8888
self.ds,
89-
input_dims={"x": 10, "y": 5},
90-
batch_dims={"x": 20, "y": 10},
89+
input_dims={'x': 10, 'y': 5},
90+
batch_dims={'x': 20, 'y': 10},
9191
concat_input_dims=concat_input_dims,
9292
)
9393

9494
@parameterized(
95-
["concat_input_dims"],
95+
['concat_input_dims'],
9696
([True, False]),
9797
)
9898
def time_input_dims_input_overlap_and_concat_input_dims(self, concat_input_dims):
@@ -102,7 +102,7 @@ def time_input_dims_input_overlap_and_concat_input_dims(self, concat_input_dims)
102102
"""
103103
BatchGenerator(
104104
self.ds,
105-
input_dims={"x": 10, "y": 10},
106-
input_overlap={"x": 5, "y": 5},
105+
input_dims={'x': 10, 'y': 10},
106+
input_overlap={'x': 5, 'y': 5},
107107
concat_input_dims=concat_input_dims,
108108
)

asv_bench/benchmarks/loaders.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ class TorchLoader:
1818
def setup(self, *args, **kwargs):
1919
self.ds = xr.Dataset(
2020
{
21-
"var1": (("x", "y"), randn_xy),
22-
"var2": (("y"), randn_y),
21+
'var1': (('x', 'y'), randn_xy),
22+
'var2': (('y'), randn_y),
2323
},
2424
coords={
25-
"x": np.arange(nx),
26-
"y": np.linspace(0, 1, ny),
25+
'x': np.arange(nx),
26+
'y': np.linspace(0, 1, ny),
2727
},
2828
)
29-
self.x_gen = BatchGenerator(self.ds["var1"], {"y": 10})
30-
self.y_gen = BatchGenerator(self.ds["var2"], {"y": 10})
29+
self.x_gen = BatchGenerator(self.ds['var1'], {'y': 10})
30+
self.y_gen = BatchGenerator(self.ds['var2'], {'y': 10})
3131

3232
def time_map_dataset(self):
3333
"""

0 commit comments

Comments
 (0)