{"action":"created","issue":{"url":"https://api.github.com/repos/scipy/scipy/issues/5256","labels_url":"https://api.github.com/repos/scipy/scipy/issues/5256/labels{/name}","comments_url":"https://api.github.com/repos/scipy/scipy/issues/5256/comments","events_url":"https://api.github.com/repos/scipy/scipy/issues/5256/events","html_url":"https://github.com/scipy/scipy/issues/5256","id":106699709,"number":5256,"title":"passing a function with keyword only arguments and no initial guess to curve_fit","user":{"login":"anntzer","id":1322974,"avatar_url":"https://avatars.githubusercontent.com/u/1322974?v=3","gravatar_id":"","url":"https://api.github.com/users/anntzer","html_url":"https://github.com/anntzer","followers_url":"https://api.github.com/users/anntzer/followers","following_url":"https://api.github.com/users/anntzer/following{/other_user}","gists_url":"https://api.github.com/users/anntzer/gists{/gist_id}","starred_url":"https://api.github.com/users/anntzer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anntzer/subscriptions","organizations_url":"https://api.github.com/users/anntzer/orgs","repos_url":"https://api.github.com/users/anntzer/repos","events_url":"https://api.github.com/users/anntzer/events{/privacy}","received_events_url":"https://api.github.com/users/anntzer/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-09-16T05:17:52Z","updated_at":"2015-09-17T18:33:25Z","closed_at":null,"body":"```\r\nfrom scipy.optimize import curve_fit\r\n\r\ndef func(x, a, *, b=1):\r\n    return a * x + b\r\n\r\nprint(curve_fit(func, [0, 1, 2], [2, 3, 4]))\r\n```\r\n\r\nThis fails because `curve_fit` tries to determine the number of arguments using `inspect.getargspec` (`ValueError: Function has keyword-only arguments or annotations, use getfullargspec() API which can support them`).  I'd suggest either defaulting to optimizing over all non-keyword-only arguments (which keeps compatibility with the case of \"standard\" optional arguments, which are also optimized over), or throwing a more explicit error (because there isn't much to do anyways if the function has a keyword-only argument without a default value)."},"comment":{"url":"https://api.github.com/repos/scipy/scipy/issues/comments/141180068","html_url":"https://github.com/scipy/scipy/issues/5256#issuecomment-141180068","issue_url":"https://api.github.com/repos/scipy/scipy/issues/5256","id":141180068,"user":{"login":"ev-br","id":2133832,"avatar_url":"https://avatars.githubusercontent.com/u/2133832?v=3","gravatar_id":"","url":"https://api.github.com/users/ev-br","html_url":"https://github.com/ev-br","followers_url":"https://api.github.com/users/ev-br/followers","following_url":"https://api.github.com/users/ev-br/following{/other_user}","gists_url":"https://api.github.com/users/ev-br/gists{/gist_id}","starred_url":"https://api.github.com/users/ev-br/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ev-br/subscriptions","organizations_url":"https://api.github.com/users/ev-br/orgs","repos_url":"https://api.github.com/users/ev-br/repos","events_url":"https://api.github.com/users/ev-br/events{/privacy}","received_events_url":"https://api.github.com/users/ev-br/received_events","type":"User","site_admin":false},"created_at":"2015-09-17T18:33:25Z","updated_at":"2015-09-17T18:33:25Z","body":"With gh-5248, the error is more explicit (at least on python 3.3+).\r\n\r\n`TypeError: f() missing 1 required keyword-only argument: 'b'`.\r\n\r\nNote that keyword-only arguments do not work with default values either: \r\n\r\n```\r\n>>> def f(x, a, *, b):\r\n...    return a*x + b\r\n>>> curve_fit(f, [0, 1, 2], [2, 3, 4], p0=[1, 2])\r\nTraceback (most recent call last):\r\n...\r\n     return function(xdata, *params) - ydata\r\nTypeError: f() takes 2 positional arguments but 3 were given\r\n```\r\n"}}