Skip to content

Commit 9f99c2d

Browse files
Fix: update deprecated scipy.integrate.trapz to trapezoid xarray-contrib#243 (xarray-contrib#262)
for more information, see https://pre-commit.ci
1 parent ca22016 commit 9f99c2d

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

.github/dependabot.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ updates:
44
directory: "/.devcontainer"
55
schedule:
66
interval: "daily"
7-
- package-ecosystem: "github-actions"
8-
directory: "/.github"
7+
- package-ecosystem: "github-actions"
8+
directory: "/.github"
99
schedule:
1010
interval: "monthly"

advanced/apply_ufunc/core-dimensions.ipynb

+4-4
Original file line numberDiff line numberDiff line change
@@ -336,19 +336,19 @@
336336
},
337337
"source": [
338338
"```{exercise}\n",
339-
":label: trapz\n",
339+
":label: trapezoid\n",
340340
"\n",
341-
"Use `apply_ufunc` to apply `scipy.integrate.trapz` along the `time` axis.\n",
341+
"Use `apply_ufunc` to apply `scipy.integrate.trapezoid` along the `time` axis.\n",
342342
"```\n",
343343
"\n",
344-
"````{solution} trapz\n",
344+
"````{solution} trapezoid\n",
345345
":class: dropdown\n",
346346
"\n",
347347
"```python\n",
348348
"import scipy as sp\n",
349349
"import scipy.integrate\n",
350350
"\n",
351-
"xr.apply_ufunc(scipy.integrate.trapz, ds, input_core_dims=[[\"time\"]], kwargs={\"axis\": -1})\n",
351+
"xr.apply_ufunc(scipy.integrate.trapezoid, ds, input_core_dims=[[\"time\"]], kwargs={\"axis\": -1})\n",
352352
"```\n",
353353
"````"
354354
]

advanced/apply_ufunc/dask_apply_ufunc.ipynb

+8-8
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,8 @@
338338
"in parallel to each block. This ability can be activated using\n",
339339
"`dask=\"parallelized\"`. \n",
340340
"\n",
341-
"We will use `scipy.integrate.trapz` as an example of a function that cannot\n",
342-
"handle dask arrays and requires a core dimension. If we call `trapz` with a dask\n",
341+
"We will use `scipy.integrate.trapezoid` as an example of a function that cannot\n",
342+
"handle dask arrays and requires a core dimension. If we call `trapezoid` with a dask\n",
343343
"array, we get a numpy array back that is, the values have been eagerly computed.\n",
344344
"This is undesirable behaviour\n"
345345
]
@@ -354,7 +354,7 @@
354354
"import scipy as sp\n",
355355
"import scipy.integrate\n",
356356
"\n",
357-
"sp.integrate.trapz(\n",
357+
"sp.integrate.trapezoid(\n",
358358
" ds.air.data, axis=ds.air.get_axis_num(\"lon\")\n",
359359
") # does NOT return a dask array, you should see activity on the dashboard"
360360
]
@@ -377,7 +377,7 @@
377377
"outputs": [],
378378
"source": [
379379
"integrated = xr.apply_ufunc(\n",
380-
" sp.integrate.trapz,\n",
380+
" sp.integrate.trapezoid,\n",
381381
" ds,\n",
382382
" input_core_dims=[[\"lon\"]],\n",
383383
" kwargs={\"axis\": -1},\n",
@@ -479,7 +479,7 @@
479479
"tags": []
480480
},
481481
"source": [
482-
"The core dimension for `trapz` is `lon`, and there is only one chunk along `lon`. This means that integrating along `lon` is a \"blockwise\" or \"embarrassingly parallel\" operation and `dask=\"parallelized\"` works quite well. \n",
482+
"The core dimension for `trapezoid` is `lon`, and there is only one chunk along `lon`. This means that integrating along `lon` is a \"blockwise\" or \"embarrassingly parallel\" operation and `dask=\"parallelized\"` works quite well. \n",
483483
"\n",
484484
"```{caution} Question\n",
485485
"Do you understand why `integrate(ds)` when `ds` has a single chunk along `lon` is a \"embarrassingly parallel\" operation?\n",
@@ -535,7 +535,7 @@
535535
"source": [
536536
"def integrate_wrapper(array, **kwargs):\n",
537537
" print(f\"received array of type {type(array)}, shape {array.shape}\")\n",
538-
" result = sp.integrate.trapz(array, **kwargs)\n",
538+
" result = sp.integrate.trapezoid(array, **kwargs)\n",
539539
" print(f\"received array of type {type(result)}, shape {result.shape}\")\n",
540540
" return result\n",
541541
"\n",
@@ -611,15 +611,15 @@
611611
"\n",
612612
"Conceptually, there is a two-way flow of information between various packages when executing `integrated.compute()`:\n",
613613
"\n",
614-
"`xarray.apply_ufunc` ↔ `dask.array.apply_gufunc` ↔ `integrate_wrapper` ↔ `scipy.integrate.trapz` ↔ `ds.air.data`\n",
614+
"`xarray.apply_ufunc` ↔ `dask.array.apply_gufunc` ↔ `integrate_wrapper` ↔ `scipy.integrate.trapezoid` ↔ `ds.air.data`\n",
615615
"\n",
616616
"\n",
617617
"When executed\n",
618618
"\n",
619619
"1. Xarray loops over all data variables.\n",
620620
"1. Xarray unwraps the underlying dask array (e.g. `ds.air`) and passes that to dask's `apply_gufunc`.\n",
621621
"1. `apply_gufunc` calls `integrate_wrapper` on each block of the array.\n",
622-
"1. For each block, `integrate_wrapper` calls `scipy.integrate.trapz` and returns one block of the output array.\n",
622+
"1. For each block, `integrate_wrapper` calls `scipy.integrate.trapezoid` and returns one block of the output array.\n",
623623
"1. dask stitches all the output blocks to form the output array.\n",
624624
"1. `xarray.apply_ufunc` wraps the output array with Xarray metadata to give the final result.\n",
625625
"\n",

0 commit comments

Comments
 (0)