xarray.DataTree.pipe#
- DataTree.pipe(func, *args, **kwargs)[source]#
Apply
func(self, *args, **kwargs)This method replicates the pandas method of the same name.
- Parameters:
func (
callable()) – function to apply to this xarray object (Dataset/DataArray).args, andkwargsare passed intofunc. Alternatively a(callable, data_keyword)tuple wheredata_keywordis a string indicating the keyword ofcallablethat expects the xarray object.*args – positional arguments passed into
func.**kwargs – a dictionary of keyword arguments passed into
func.
- Returns:
object (
T) – the return type offunc.
Notes
Use
.pipewhen chaining together functions that expect xarray or pandas objects, e.g., instead of writingf(g(h(dt), arg1=a), arg2=b, arg3=c)
You can write
(dt.pipe(h).pipe(g, arg1=a).pipe(f, arg2=b, arg3=c))
If you have a function that takes the data as (say) the second argument, pass a tuple indicating which keyword expects the data. For example, suppose
ftakes its data asarg2:(dt.pipe(h).pipe(g, arg1=a).pipe((f, "arg2"), arg1=a, arg3=c))