Skip to content

DOC fix kwargs parameter name in curvefit docstrings - #11536

Open
advitrocks9 wants to merge 2 commits into
pydata:mainfrom
advitrocks9:curvefit-kwargs-docstring
Open

DOC fix kwargs parameter name in curvefit docstrings#11536
advitrocks9 wants to merge 2 commits into
pydata:mainfrom
advitrocks9:curvefit-kwargs-docstring

Conversation

@advitrocks9

Copy link
Copy Markdown

Description

Fixes #6891.

Dataset.curvefit and DataArray.curvefit both document their scipy passthrough as
**kwargs : optional, so calling them the way the docstring describes fails:

import numpy as np
import xarray as xr

def exp(t, a, b):
    return a * np.exp(b * t)

t = np.linspace(0, 1, 20)
da = xr.DataArray(exp(t, 2.0, -1.0), dims="t", coords={"t": t})
da.curvefit("t", exp, method="trf")
TypeError: DataArray.curvefit() got an unexpected keyword argument 'method'

Same on Dataset. Neither method actually has a VAR_KEYWORD parameter, they take a single kwargs: dict[str, Any] | None = None, and kwargs={"method": "trf"} works fine. So the docstrings are wrong, not the behaviour. computation/fit.py,
which both methods delegate to, already documents the parameter correctly, the class docstrings
just drifted from it in #5182. headtr1ck
scoped this fix on the issue:
change **kwargs to kwargs in both docstrings.

Checklist

Both methods take a collecting `kwargs: dict[str, Any] | None = None`, not
`**kwargs`, so calling them the way the docstring describes raises TypeError.
`xarray/computation/fit.py`, which both delegate to, already spells it
correctly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Passing extra keyword arguments to curvefit throws an exception.

1 participant