Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
boundary_kwargs = dict(boundary=boundary, fill_value=fill_value)
# now pad / trim the data as necessary
# here we enumerate all the valid possible shifts
if (pos == "center" and to == "right") or (pos == "left" and to == "center"):
# do nothing, this is the default for how cumsum works
data = da_cum.data
elif (pos == "center" and to == "left") or (pos == "right" and to == "center"):
data = _pad_array(
da_cum.isel(**{dim: slice(0, -1)}), dim, left=True, **boundary_kwargs
)
elif (pos == "center" and to == "inner") or (pos == "outer" and to == "center"):
data = da_cum.isel(**{dim: slice(0, -1)}).data
elif (pos == "center" and to == "outer") or (pos == "inner" and to == "center"):
data = _pad_array(da_cum, dim, left=True, **boundary_kwargs)
else:
raise ValueError(
"From `%s` to `%s` is not a valid position "
"shift for cumsum operation." % (pos, to)
)
da_cum_newcoord = self._wrap_and_replace_coords(da, data, to, keep_coords)
return da_cum_newcoord
if to is None:
to = self._default_shifts[pos]
# first use xarray's cumsum method
da_cum = da.cumsum(dim=dim)
boundary_kwargs = dict(boundary=boundary, fill_value=fill_value)
# now pad / trim the data as necessary
# here we enumerate all the valid possible shifts
if (pos == "center" and to == "right") or (pos == "left" and to == "center"):
# do nothing, this is the default for how cumsum works
data = da_cum.data
elif (pos == "center" and to == "left") or (pos == "right" and to == "center"):
data = _pad_array(
da_cum.isel(**{dim: slice(0, -1)}), dim, left=True, **boundary_kwargs
)
elif (pos == "center" and to == "inner") or (pos == "outer" and to == "center"):
data = da_cum.isel(**{dim: slice(0, -1)}).data
elif (pos == "center" and to == "outer") or (pos == "inner" and to == "center"):
data = _pad_array(da_cum, dim, left=True, **boundary_kwargs)
else:
raise ValueError(
"From `%s` to `%s` is not a valid position "
"shift for cumsum operation." % (pos, to)
)
da_cum_newcoord = self._wrap_and_replace_coords(da, data, to, keep_coords)
return da_cum_newcoord