xarray.Dataset.pipe¶
-
Dataset.
pipe
(func: Union[Callable[[...], T], Tuple[Callable[[...], T], str]], *args, **kwargs) → T¶ Apply func(self, *args, **kwargs)
This method replicates the pandas method of the same name.
- Parameters
- funcfunction
function to apply to this xarray object (Dataset/DataArray).
args
, andkwargs
are passed intofunc
. Alternatively a(callable, data_keyword)
tuple wheredata_keyword
is a string indicating the keyword ofcallable
that expects the xarray object.- argspositional arguments passed into
func
. - kwargsa dictionary of keyword arguments passed into
func
.
- Returns
- objectthe return type of
func
.
- objectthe return type of
See also
Notes
Use
.pipe
when chaining together functions that expect xarray or pandas objects, e.g., instead of writing>>> f(g(h(ds), arg1=a), arg2=b, arg3=c)
You can write
>>> (ds.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
f
takes its data asarg2
:>>> (ds.pipe(h) ... .pipe(g, arg1=a) ... .pipe((f, 'arg2'), arg1=a, arg3=c) ... )