MCPcopy
hub / github.com/pydata/xarray / series_reduce

Function series_reduce

xarray/tests/test_duck_array_ops.py:412–434  ·  view source on GitHub ↗

convert DataArray to pd.Series, apply pd.func, then convert back to a DataArray. Multiple dims cannot be specified.

(da, func, dim, **kwargs)

Source from the content-addressed store, hash-verified

410
411
412def series_reduce(da, func, dim, **kwargs):
413 """convert DataArray to pd.Series, apply pd.func, then convert back to
414 a DataArray. Multiple dims cannot be specified."""
415
416 # pd no longer accepts skipna=None https://github.com/pandas-dev/pandas/issues/44178
417 if kwargs.get("skipna", True) is None:
418 kwargs["skipna"] = True
419
420 if dim is None or da.ndim == 1:
421 se = da.to_series()
422 return from_series_or_scalar(getattr(se, func)(**kwargs))
423 else:
424 dims = list(da.dims)
425 dims.remove(dim)
426 d = dims[0]
427 da1 = [
428 series_reduce(da.isel(**{d: i}), func, dim, **kwargs)
429 for i in range(len(da[d]))
430 ]
431
432 if d in da.coords:
433 return concat(da1, dim=da[d])
434 return concat(da1, dim=d)
435
436
437def assert_dask_array(da, dask):

Callers 2

test_reduceFunction · 0.85
test_min_countFunction · 0.85

Calls 5

concatFunction · 0.90
from_series_or_scalarFunction · 0.85
to_seriesMethod · 0.80
getMethod · 0.45
iselMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…