Skip to content

Reduction APIs for groupby, groupby_bins, resample, rolling #2363

Closed
@fujiisoup

Description

@fujiisoup

From #2356

APIs for groupby, groupby_bins, resample, rolling are different, especially for multi-dimensional array.

import numpy as np
import xarray as xr
import pandas as pd

time = pd.date_range('2000-01-01', freq='6H', periods=365 * 4)
ds = xr.Dataset({'foo': (('time', 'x'), np.random.randn(365 * 4, 5)), 'time': time, 
                 'x': [0, 1, 2, 1, 0]})

ds.rolling(time=2).mean()  # result dims : ('time', 'x')
ds.resample(time='M').mean()  # result dims : ('time', 'x')
ds['foo'].resample(time='M').mean()  # result dims : ('time', )  maybe a bug #2362
ds.groupby('time.month').mean()  # result dims : ('month', )
ds.groupby_bins('time', 3).mean()  # result dims : ('time_bins', )
  • In rolling and resample(for Dataset), reduction without argument is carried out along grouped dimension
  • In rolling, reduction along other dimesnion is not possible
  • In groupby and groupby_bins, reduction is applied to the grouped objects and if without argument, it reduces alongall the dimensions of each grouped object.

I think rollings API is most clean, but I am not sure it is worth to change these APIs.

The possible options would be

  1. Change APIs of groupby and groupby_bins so that they share similar API with rolling.
  2. Document clearly how to perform resample or groupby with multidimensional arrays.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions