Skip to content

Commit

Permalink
Update pre-commit hooks (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
andersy005 authored Aug 9, 2024
1 parent c3ececf commit 72d9960
Show file tree
Hide file tree
Showing 21 changed files with 442 additions and 392 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ target/

# tests
.pytest_cache/*
.mypy_cache/
23 changes: 6 additions & 17 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,20 @@ repos:
exclude: "asv_bench/asv.conf.json"
- id: check-yaml

- repo: https://github.com/psf/black
rev: 24.4.2
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.5.5"
hooks:
- id: black-jupyter

- repo: https://github.com/PyCQA/flake8
rev: 7.1.0
hooks:
- id: flake8
- repo: https://github.com/asottile/seed-isort-config
rev: v2.2.0
hooks:
- id: seed-isort-config
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
- id: ruff
args: ["--fix"]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
hooks:
- id: prettier

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.1
rev: v1.11.0
hooks:
- id: mypy
additional_dependencies: [
Expand Down
12 changes: 6 additions & 6 deletions asv_bench/benchmarks/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ class Accessor:
def setup(self, *args, **kwargs):
self.ds = xr.Dataset(
{
"var1": (("x", "y", "t"), randn_xyt),
'var1': (('x', 'y', 't'), randn_xyt),
},
coords={
"x": np.arange(nx),
"y": np.linspace(0, 1, ny),
"t": pd.date_range("1970-01-01", periods=nt, freq="D"),
'x': np.arange(nx),
'y': np.linspace(0, 1, ny),
't': pd.date_range('1970-01-01', periods=nt, freq='D'),
},
)

@parameterized(
["input_dims"],
([{"x": 10}, {"x": 10, "y": 5}, {"x": 10, "y": 5, "t": 2}],),
['input_dims'],
([{'x': 10}, {'x': 10, 'y': 5}, {'x': 10, 'y': 5, 't': 2}],),
)
def time_input_dims(self, input_dims):
"""
Expand Down
30 changes: 15 additions & 15 deletions asv_bench/benchmarks/batches.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ class Base:
def setup(self):
self.ds = xr.Dataset(
{
"var1": (("x", "y", "t"), randn_xyt),
'var1': (('x', 'y', 't'), randn_xyt),
},
coords={
"x": np.arange(nx),
"y": np.linspace(0, 1, ny),
"t": pd.date_range("1970-01-01", periods=nt, freq="D"),
'x': np.arange(nx),
'y': np.linspace(0, 1, ny),
't': pd.date_range('1970-01-01', periods=nt, freq='D'),
},
)

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

def setup(self):
super().setup()
ds_dask = self.ds.chunk({"t": 2})
self.bg = BatchGenerator(ds_dask, input_dims={"t": 2}, preload_batch=False)
ds_dask = self.ds.chunk({'t': 2})
self.bg = BatchGenerator(ds_dask, input_dims={'t': 2}, preload_batch=False)

def time_next_batch(self):
"""
Expand All @@ -51,7 +51,7 @@ class OneInputDim(Base):

def setup(self):
super().setup()
self.bg = BatchGenerator(self.ds, input_dims={"x": 10})
self.bg = BatchGenerator(self.ds, input_dims={'x': 10})

def time_next_batch(self):
"""
Expand All @@ -67,7 +67,7 @@ class AllInputDim(Base):

def setup(self):
super().setup()
self.bg = BatchGenerator(self.ds, input_dims={"x": 10, "y": 10, "t": 5})
self.bg = BatchGenerator(self.ds, input_dims={'x': 10, 'y': 10, 't': 5})

def time_next_batch(self):
"""
Expand All @@ -84,7 +84,7 @@ class InputDimInputOverlap(Base):
def setup(self):
super().setup()
self.bg = BatchGenerator(
self.ds, input_dims={"x": 10, "y": 10}, input_overlap={"x": 5, "y": 5}
self.ds, input_dims={'x': 10, 'y': 10}, input_overlap={'x': 5, 'y': 5}
)

def time_next_batch(self):
Expand All @@ -102,7 +102,7 @@ class InputDimConcat(Base):
def setup(self):
super().setup()
self.bg = BatchGenerator(
self.ds, input_dims={"x": 10, "y": 10}, concat_input_dims=True
self.ds, input_dims={'x': 10, 'y': 10}, concat_input_dims=True
)

def time_next_batch(self):
Expand All @@ -120,7 +120,7 @@ class InputDimBatchDim(Base):
def setup(self):
super().setup()
self.bg = BatchGenerator(
self.ds, input_dims={"x": 10, "y": 10}, batch_dims={"t": 2}
self.ds, input_dims={'x': 10, 'y': 10}, batch_dims={'t': 2}
)

def time_next_batch(self):
Expand All @@ -139,8 +139,8 @@ def setup(self):
super().setup()
self.bg = BatchGenerator(
self.ds,
input_dims={"x": 5, "y": 5},
batch_dims={"x": 10, "y": 10},
input_dims={'x': 5, 'y': 5},
batch_dims={'x': 10, 'y': 10},
concat_input_dims=True,
)

Expand All @@ -160,8 +160,8 @@ def setup(self):
super().setup()
self.bg = BatchGenerator(
self.ds,
input_dims={"x": 10, "y": 10},
input_overlap={"x": 5, "y": 5},
input_dims={'x': 10, 'y': 10},
input_overlap={'x': 5, 'y': 5},
concat_input_dims=True,
)

Expand Down
42 changes: 21 additions & 21 deletions asv_bench/benchmarks/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ class Generator:
def setup(self, *args, **kwargs):
self.ds = xr.Dataset(
{
"var1": (("x", "y", "t"), randn_xyt),
'var1': (('x', 'y', 't'), randn_xyt),
},
coords={
"x": np.arange(nx),
"y": np.linspace(0, 1, ny),
"t": pd.date_range("1970-01-01", periods=nt, freq="D"),
'x': np.arange(nx),
'y': np.linspace(0, 1, ny),
't': pd.date_range('1970-01-01', periods=nt, freq='D'),
},
)

@parameterized(["preload_batch"], ([True, False]))
@parameterized(['preload_batch'], ([True, False]))
def time_batch_preload(self, preload_batch):
"""
Construct a generator on a chunked DataSet with and without preloading
batches.
"""
ds_dask = self.ds.chunk({"t": 2})
BatchGenerator(ds_dask, input_dims={"t": 2}, preload_batch=preload_batch)
ds_dask = self.ds.chunk({'t': 2})
BatchGenerator(ds_dask, input_dims={'t': 2}, preload_batch=preload_batch)

@parameterized(
["input_dims"],
([{"x": 10}, {"x": 10, "y": 5}, {"x": 10, "y": 5, "t": 2}],),
['input_dims'],
([{'x': 10}, {'x': 10, 'y': 5}, {'x': 10, 'y': 5, 't': 2}],),
)
def time_input_dims(self, input_dims):
"""
Expand All @@ -53,30 +53,30 @@ def time_input_dims_and_input_overlap(self):
Benchmark simple batch generation case.
"""
BatchGenerator(
self.ds, input_dims={"x": 10, "y": 10}, input_overlap={"x": 5, "y": 5}
self.ds, input_dims={'x': 10, 'y': 10}, input_overlap={'x': 5, 'y': 5}
)

@parameterized(["concat_input_dims"], (["True", "False"]))
@parameterized(['concat_input_dims'], (['True', 'False']))
def time_input_dims_and_concat_input_dims(self, concat_input_dims):
"""
Benchmark concat_input_dims
"""
BatchGenerator(
self.ds, input_dims={"x": 10, "y": 5}, concat_input_dims=concat_input_dims
self.ds, input_dims={'x': 10, 'y': 5}, concat_input_dims=concat_input_dims
)

@parameterized(
["input_dims", "batch_dims"],
([{"x": 10}, {"x": 10, "y": 5}],),
['input_dims', 'batch_dims'],
([{'x': 10}, {'x': 10, 'y': 5}],),
)
def time_input_dims_and_batch_dims(self, input_dims):
"""
Benchmark batch generator with input_dims and batch_dims.
"""
BatchGenerator(self.ds, input_dims=input_dims, batch_dims={"t": 2})
BatchGenerator(self.ds, input_dims=input_dims, batch_dims={'t': 2})

@parameterized(
["concat_input_dims"],
['concat_input_dims'],
([True, False]),
)
def time_input_dims_batch_dims_and_concat_input_dims(self, concat_input_dims):
Expand All @@ -86,13 +86,13 @@ def time_input_dims_batch_dims_and_concat_input_dims(self, concat_input_dims):
"""
BatchGenerator(
self.ds,
input_dims={"x": 10, "y": 5},
batch_dims={"x": 20, "y": 10},
input_dims={'x': 10, 'y': 5},
batch_dims={'x': 20, 'y': 10},
concat_input_dims=concat_input_dims,
)

@parameterized(
["concat_input_dims"],
['concat_input_dims'],
([True, False]),
)
def time_input_dims_input_overlap_and_concat_input_dims(self, concat_input_dims):
Expand All @@ -102,7 +102,7 @@ def time_input_dims_input_overlap_and_concat_input_dims(self, concat_input_dims)
"""
BatchGenerator(
self.ds,
input_dims={"x": 10, "y": 10},
input_overlap={"x": 5, "y": 5},
input_dims={'x': 10, 'y': 10},
input_overlap={'x': 5, 'y': 5},
concat_input_dims=concat_input_dims,
)
12 changes: 6 additions & 6 deletions asv_bench/benchmarks/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ class TorchLoader:
def setup(self, *args, **kwargs):
self.ds = xr.Dataset(
{
"var1": (("x", "y"), randn_xy),
"var2": (("y"), randn_y),
'var1': (('x', 'y'), randn_xy),
'var2': (('y'), randn_y),
},
coords={
"x": np.arange(nx),
"y": np.linspace(0, 1, ny),
'x': np.arange(nx),
'y': np.linspace(0, 1, ny),
},
)
self.x_gen = BatchGenerator(self.ds["var1"], {"y": 10})
self.y_gen = BatchGenerator(self.ds["var2"], {"y": 10})
self.x_gen = BatchGenerator(self.ds['var1'], {'y': 10})
self.y_gen = BatchGenerator(self.ds['var2'], {'y': 10})

def time_map_dataset(self):
"""
Expand Down
Loading

0 comments on commit 72d9960

Please sign in to comment.