pydata / pydata/xarray

Feature: Aggregate using one or more operations over the specified axis.

Open
#9,479 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement topic-groupby
Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

Is your feature request related to a problem?

I'm always frustrated when I need to resample a ds and the resampling method is different for the variables present, i.e. for one variable I want the sum and for the other the mean.

Describe the solution you'd like

Ideally there would be some functionality similar to pandas .agg functionality.
Not sure if this is feasible.

ds = ds.resample(time="D").agg({"pr":"sum","tas":np.mean})
Describe alternatives you've considered

Current workaround which gets unwieldy for multiple variables.

ds_pr = ds.pr.resample(time="D").sum()
ds_tas = ds.tas.resample(time="D").mean()

ds = xr.merge([ds_pr, ds_tas])
Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Dataset resample entry point and compare the requested API with pandas aggregation behavior. Define how mappings of variables to operations should work, including the shown sum and mean case, then add coverage for the new behavior. Done means one resampling call can apply different operations to the specified variables without the manual merge workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, pandas, python
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.