pydata / pydata/xarray

Passing extra keyword arguments to `curvefit` throws an exception.

Open
#6,891 13 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

contrib-good-first-issue topic-documentation
Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

What happened?

Just like the title says, passing an extra keyword argument corresponding to scipy's curve_fit throws an exception. The documentation has a parameter section that says:

*kwargs (optional) – Additional keyword arguments to passed to scipy curve_fit

So if one specifies a method="trf" keyword argument to the .curvefit method, you get an error: TypeError: curvefit() got an unexpected keyword argument 'method'

The only way it works as expected is if I pass the keyword arguments as dictionary elements via a kwargs argument like so: kwargs={"method": "trf"}. This behaviour contradicts what is mentioned in the docstring.

What did you expect to happen?

No error thrown

Minimal Complete Verifiable Example
import pandas as pd
import xarray as xr
import numpy as np

da = xr.DataArray(

    np.random.rand(4, 3),

    [

        ("time", pd.date_range("2000-01-01", periods=4)),

        ("space", ["IA", "IL", "IN"]),

    ],

)
da.curvefit(coords=["time"], func=lambda x, params: x, method="trf")
MVCE confirmation
  • Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • Complete example — the example is self-contained, including all data and the text of any traceback.
  • Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • New issue — a search of GitHub Issues suggests this is not a duplicate.
Relevant log output
TypeError: curvefit() got an unexpected keyword argument 'method'
Anything else we need to know?

No response

Environment
```shell commit: None python: 3.8.12 | packaged by conda-forge | (default, Jan 30 2022, 23:42:07) [GCC 9.4.0] python-bits: 64 OS: Linux OS-release: 5.4.0-1061-aws machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: C.UTF-8 LOCALE: ('en_US', 'UTF-8') libhdf5: 1.12.1 libnetcdf: 4.8.1

xarray: 2022.3.0
pandas: 1.4.3
numpy: 1.22.0
scipy: 1.6.2
netCDF4: 1.6.0
pydap: None
h5netcdf: 0.15.0
h5py: 3.7.0
Nio: None
zarr: 2.10.3
cftime: 1.6.1
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: 0.9.10.1
iris: None
bottleneck: None
dask: 2022.03.0
distributed: 2022.3.0
matplotlib: None
cartopy: None
seaborn: None
numbagg: None
fsspec: 2022.01.0
cupy: None
pint: None
sparse: 0.13.0
setuptools: 63.1.0
pip: 22.2.2
conda: None
pytest: 6.2.5
IPython: 8.4.0
sphinx: None

</details>

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 DataArray.curvefit entry point and compare its documented *kwargs behavior with the scipy curve_fit call described in the issue. Verify the existing kwargs dictionary form and the direct method="trf" form, then run the curvefit tests or a minimal example to confirm that the documented call completes without an unexpected-keyword error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, data
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.