MCPcopy Index your code
hub / github.com/pydata/xarray / map

Method map

xarray/core/resample.py:305–366  ·  view source on GitHub ↗

Apply a function to each array in the group and concatenate them together into a new array. `func` is called like `func(ar, *args, **kwargs)` for each array `ar` in this group. Apply uses heuristics (like `pandas.GroupBy.apply`) to figure out how to stack to

(
        self,
        func: Callable[..., Any],
        args: tuple[Any, ...] = (),
        shortcut: bool | None = False,
        **kwargs: Any,
    )

Source from the content-addressed store, hash-verified

303 )
304
305 def map(
306 self,
307 func: Callable[..., Any],
308 args: tuple[Any, ...] = (),
309 shortcut: bool | None = False,
310 **kwargs: Any,
311 ) -> DataArray:
312 """Apply a function to each array in the group and concatenate them
313 together into a new array.
314
315 `func` is called like `func(ar, *args, **kwargs)` for each array `ar`
316 in this group.
317
318 Apply uses heuristics (like `pandas.GroupBy.apply`) to figure out how
319 to stack together the array. The rule is:
320
321 1. If the dimension along which the group coordinate is defined is
322 still in the first grouped array after applying `func`, then stack
323 over this dimension.
324 2. Otherwise, stack over the new dimension given by name of this
325 grouping (the argument to the `groupby` function).
326
327 Parameters
328 ----------
329 func : callable
330 Callable to apply to each array.
331 shortcut : bool, optional
332 Whether or not to shortcut evaluation under the assumptions that:
333
334 (1) The action of `func` does not depend on any of the array
335 metadata (attributes or coordinates) but only on the data and
336 dimensions.
337 (2) The action of `func` creates arrays with homogeneous metadata,
338 that is, with the same dimensions and attributes.
339
340 If these conditions are satisfied `shortcut` provides significant
341 speedup. This should be the case for many common groupby operations
342 (e.g., applying numpy ufuncs).
343 args : tuple, optional
344 Positional arguments passed on to `func`.
345 **kwargs
346 Used to call `func(ar, **kwargs)` for each array `ar`.
347
348 Returns
349 -------
350 applied : DataArray
351 The result of splitting, applying and combining this array.
352 """
353 # TODO: the argument order for Resample doesn't match that for its parent,
354 # GroupBy
355 combined = super().map(func, shortcut=shortcut, args=args, **kwargs)
356
357 # If the aggregation function didn't drop the original resampling
358 # dimension, then we need to do so before we can rename the proxy
359 # dimension we used.
360 if self._dim in combined.coords:
361 combined = combined.drop_vars([self._dim])
362

Callers 1

applyMethod · 0.95

Calls 3

mapMethod · 0.45
drop_varsMethod · 0.45
renameMethod · 0.45

Tested by

no test coverage detected