MCPcopy Index your code
hub / github.com/pydata/xarray / _get_func_args

Function _get_func_args

xarray/computation/fit.py:33–56  ·  view source on GitHub ↗

Use `inspect.signature` to try accessing `func` args. Otherwise, ensure they are provided by user.

(func, param_names)

Source from the content-addressed store, hash-verified

31
32
33def _get_func_args(func, param_names):
34 """Use `inspect.signature` to try accessing `func` args. Otherwise, ensure
35 they are provided by user.
36 """
37 func_args: Union[dict[str, Parameter], MappingProxyType[str, Parameter]]
38 try:
39 func_args = inspect.signature(func).parameters
40 except ValueError as err:
41 func_args = {} # type: ignore[assignment,unused-ignore]
42 if not param_names:
43 raise ValueError(
44 "Unable to inspect `func` signature, and `param_names` was not provided."
45 ) from err
46 if param_names:
47 params = param_names
48 else:
49 params = list(func_args)[1:]
50 if any(
51 (p.kind in [p.VAR_POSITIONAL, p.VAR_KEYWORD]) for p in func_args.values()
52 ):
53 raise ValueError(
54 "`param_names` must be provided because `func` takes variable length arguments."
55 )
56 return params, func_args
57
58
59def _initialize_curvefit_params(params, p0, bounds, func_args):

Callers 2

test_curvefit_helpersMethod · 0.90
curvefitFunction · 0.70

Calls 1

valuesMethod · 0.45

Tested by 1

test_curvefit_helpersMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…