Skip to content

Commit aded14b

Browse files
Update pre-commit hooks to use latest versions of ruff and mypy (#236)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent bbe3499 commit aded14b

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ repos:
1414
- id: check-yaml
1515

1616
- repo: https://github.com/astral-sh/ruff-pre-commit
17-
rev: "v0.5.5"
17+
rev: "v0.6.4"
1818
hooks:
1919
- id: ruff
2020
args: ["--fix"]
@@ -26,13 +26,12 @@ repos:
2626
- id: prettier
2727

2828
- repo: https://github.com/pre-commit/mirrors-mypy
29-
rev: v1.11.0
29+
rev: v1.11.2
3030
hooks:
3131
- id: mypy
3232
additional_dependencies: [
3333
# Type stubs
3434
types-setuptools,
35-
types-pkg_resources,
3635
# Dependencies that are typed
3736
numpy,
3837
xarray,

doc/demo.ipynb

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"outputs": [],
2727
"source": [
2828
"import xarray as xr\n",
29+
"\n",
2930
"import xbatcher"
3031
]
3132
},
@@ -46,12 +47,12 @@
4647
"metadata": {},
4748
"outputs": [],
4849
"source": [
49-
"store = \"az://carbonplan-share/example_cmip6_data.zarr\"\n",
50+
"store = 'az://carbonplan-share/example_cmip6_data.zarr'\n",
5051
"ds = xr.open_dataset(\n",
5152
" store,\n",
52-
" engine=\"zarr\",\n",
53+
" engine='zarr',\n",
5354
" chunks={},\n",
54-
" backend_kwargs={\"storage_options\": {\"account_name\": \"carbonplan\"}},\n",
55+
" backend_kwargs={'storage_options': {'account_name': 'carbonplan'}},\n",
5556
")\n",
5657
"\n",
5758
"# the attributes contain a lot of useful information, but clutter the print out when we inspect the outputs\n",
@@ -98,10 +99,10 @@
9899
"\n",
99100
"bgen = xbatcher.BatchGenerator(\n",
100101
" ds=ds,\n",
101-
" input_dims={\"time\": n_timepoint_in_each_sample},\n",
102+
" input_dims={'time': n_timepoint_in_each_sample},\n",
102103
")\n",
103104
"\n",
104-
"print(f\"{len(bgen)} batches\")"
105+
"print(f'{len(bgen)} batches')"
105106
]
106107
},
107108
{
@@ -133,7 +134,7 @@
133134
"outputs": [],
134135
"source": [
135136
"expected_n_batch = len(ds.time) / n_timepoint_in_each_sample\n",
136-
"print(f\"Expecting {expected_n_batch} batches, getting {len(bgen)} batches\")"
137+
"print(f'Expecting {expected_n_batch} batches, getting {len(bgen)} batches')"
137138
]
138139
},
139140
{
@@ -153,7 +154,7 @@
153154
"source": [
154155
"expected_batch_size = len(ds.lat) * len(ds.lon)\n",
155156
"print(\n",
156-
" f\"Expecting {expected_batch_size} samples per batch, getting {len(batch.sample)} samples per batch\"\n",
157+
" f'Expecting {expected_batch_size} samples per batch, getting {len(batch.sample)} samples per batch'\n",
157158
")"
158159
]
159160
},
@@ -179,12 +180,12 @@
179180
"\n",
180181
"bgen = xbatcher.BatchGenerator(\n",
181182
" ds=ds,\n",
182-
" input_dims={\"time\": n_timepoint_in_each_sample},\n",
183-
" batch_dims={\"time\": n_timepoint_in_each_batch},\n",
183+
" input_dims={'time': n_timepoint_in_each_sample},\n",
184+
" batch_dims={'time': n_timepoint_in_each_batch},\n",
184185
" concat_input_dims=True,\n",
185186
")\n",
186187
"\n",
187-
"print(f\"{len(bgen)} batches\")"
188+
"print(f'{len(bgen)} batches')"
188189
]
189190
},
190191
{
@@ -217,11 +218,11 @@
217218
"source": [
218219
"n_timepoint_in_batch = 31\n",
219220
"\n",
220-
"bgen = xbatcher.BatchGenerator(ds=ds, input_dims={\"time\": n_timepoint_in_batch})\n",
221+
"bgen = xbatcher.BatchGenerator(ds=ds, input_dims={'time': n_timepoint_in_batch})\n",
221222
"\n",
222223
"for batch in bgen:\n",
223-
" print(f\"last time point in ds is {ds.time[-1].values}\")\n",
224-
" print(f\"last time point in batch is {batch.time[-1].values}\")\n",
224+
" print(f'last time point in ds is {ds.time[-1].values}')\n",
225+
" print(f'last time point in batch is {batch.time[-1].values}')\n",
225226
"batch"
226227
]
227228
},
@@ -249,15 +250,15 @@
249250
"\n",
250251
"bgen = xbatcher.BatchGenerator(\n",
251252
" ds=ds,\n",
252-
" input_dims={\"time\": n_timepoint_in_each_sample},\n",
253-
" batch_dims={\"time\": n_timepoint_in_each_batch},\n",
253+
" input_dims={'time': n_timepoint_in_each_sample},\n",
254+
" batch_dims={'time': n_timepoint_in_each_batch},\n",
254255
" concat_input_dims=True,\n",
255-
" input_overlap={\"time\": input_overlap},\n",
256+
" input_overlap={'time': input_overlap},\n",
256257
")\n",
257258
"\n",
258259
"batch = bgen[0]\n",
259260
"\n",
260-
"print(f\"{len(bgen)} batches\")\n",
261+
"print(f'{len(bgen)} batches')\n",
261262
"batch"
262263
]
263264
},
@@ -283,10 +284,10 @@
283284
"display(pixel)\n",
284285
"\n",
285286
"print(\n",
286-
" f\"sample 1 goes from {pixel.isel(input_batch=0).time[0].values} to {pixel.isel(input_batch=0).time[-1].values}\"\n",
287+
" f'sample 1 goes from {pixel.isel(input_batch=0).time[0].values} to {pixel.isel(input_batch=0).time[-1].values}'\n",
287288
")\n",
288289
"print(\n",
289-
" f\"sample 2 goes from {pixel.isel(input_batch=1).time[0].values} to {pixel.isel(input_batch=1).time[-1].values}\"\n",
290+
" f'sample 2 goes from {pixel.isel(input_batch=1).time[0].values} to {pixel.isel(input_batch=1).time[-1].values}'\n",
290291
")"
291292
]
292293
},
@@ -310,28 +311,28 @@
310311
"outputs": [],
311312
"source": [
312313
"bgen = xbatcher.BatchGenerator(\n",
313-
" ds=ds[[\"tasmax\"]].isel(lat=slice(0, 18), lon=slice(0, 18), time=slice(0, 30)),\n",
314-
" input_dims={\"lat\": 9, \"lon\": 9, \"time\": 10},\n",
315-
" batch_dims={\"lat\": 18, \"lon\": 18, \"time\": 15},\n",
314+
" ds=ds[['tasmax']].isel(lat=slice(0, 18), lon=slice(0, 18), time=slice(0, 30)),\n",
315+
" input_dims={'lat': 9, 'lon': 9, 'time': 10},\n",
316+
" batch_dims={'lat': 18, 'lon': 18, 'time': 15},\n",
316317
" concat_input_dims=True,\n",
317-
" input_overlap={\"lat\": 8, \"lon\": 8, \"time\": 9},\n",
318+
" input_overlap={'lat': 8, 'lon': 8, 'time': 9},\n",
318319
")\n",
319320
"\n",
320321
"for i, batch in enumerate(bgen):\n",
321-
" print(f\"batch {i}\")\n",
322+
" print(f'batch {i}')\n",
322323
" # make sure the ordering of dimension is consistent\n",
323-
" batch = batch.transpose(\"input_batch\", \"lat_input\", \"lon_input\", \"time_input\")\n",
324+
" batch = batch.transpose('input_batch', 'lat_input', 'lon_input', 'time_input')\n",
324325
"\n",
325326
" # only use the first 9 time points as features, since the last time point is the label to be predicted\n",
326327
" features = batch.tasmax.isel(time_input=slice(0, 9))\n",
327328
" # select the center pixel at the last time point to be the label to be predicted\n",
328329
" # the actual lat/lon/time for each of the sample can be accessed in labels.coords\n",
329330
" labels = batch.tasmax.isel(lat_input=5, lon_input=5, time_input=9)\n",
330331
"\n",
331-
" print(\"feature shape\", features.shape)\n",
332-
" print(\"label shape\", labels.shape)\n",
333-
" print(\"shape of lat of each sample\", labels.coords[\"lat\"].shape)\n",
334-
" print(\"\")"
332+
" print('feature shape', features.shape)\n",
333+
" print('label shape', labels.shape)\n",
334+
" print('shape of lat of each sample', labels.coords['lat'].shape)\n",
335+
" print('')"
335336
]
336337
},
337338
{
@@ -350,21 +351,21 @@
350351
"outputs": [],
351352
"source": [
352353
"for i, batch in enumerate(bgen):\n",
353-
" print(f\"batch {i}\")\n",
354+
" print(f'batch {i}')\n",
354355
" # make sure the ordering of dimension is consistent\n",
355-
" batch = batch.transpose(\"input_batch\", \"lat_input\", \"lon_input\", \"time_input\")\n",
356+
" batch = batch.transpose('input_batch', 'lat_input', 'lon_input', 'time_input')\n",
356357
"\n",
357358
" # only use the first 9 time points as features, since the last time point is the label to be predicted\n",
358359
" features = batch.tasmax.isel(time_input=slice(0, 9))\n",
359-
" features = features.stack(features=[\"lat_input\", \"lon_input\", \"time_input\"])\n",
360+
" features = features.stack(features=['lat_input', 'lon_input', 'time_input'])\n",
360361
"\n",
361362
" # select the center pixel at the last time point to be the label to be predicted\n",
362363
" # the actual lat/lon/time for each of the sample can be accessed in labels.coords\n",
363364
" labels = batch.tasmax.isel(lat_input=5, lon_input=5, time_input=9)\n",
364365
"\n",
365-
" print(\"feature shape\", features.shape)\n",
366-
" print(\"label shape\", labels.shape)\n",
367-
" print(\"shape of lat of each sample\", labels.coords[\"lat\"].shape, \"\\n\")"
366+
" print('feature shape', features.shape)\n",
367+
" print('label shape', labels.shape)\n",
368+
" print('shape of lat of each sample', labels.coords['lat'].shape, '\\n')"
368369
]
369370
},
370371
{

0 commit comments

Comments
 (0)