Skip to content

Inconsistent signature of apply #2412

@maaleske

Description

@maaleske

Dataset.apply allows passing positional arguments to func as args=(), whereas DataArrayGroupBy.apply and DatasetGroupBy.apply do not. The documentation also incorrectly suggests that the reverse is true:

Dataset.apply:

xarray/xarray/core/dataset.py

Lines 2832 to 2840 in 4de8dbc

def apply(self, func, keep_attrs=False, args=(), **kwargs):
"""Apply a function over the data variables in this dataset.
Parameters
----------
func : function
Function which can be called in the form `f(x, **kwargs)` to
transform each DataArray `x` in this dataset into another
DataArray.

DataArrayGroupBy.apply:

def apply(self, func, shortcut=False, **kwargs):
"""Apply a function over 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.

DatasetGroupBy.apply:

def apply(self, func, **kwargs):
"""Apply a function over each Dataset in the group and concatenate them
together into a new Dataset.
`func` is called like `func(ds, *args, **kwargs)` for each dataset `ds`
in this group.

I feel that funcs passed to GroupBy objects are generally equally deserving of positional arguments, and I don't see a reason why this isn't the case.

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