{"action":"created","issue":{"url":"https://api.github.com/repos/hgrecco/pint/issues/461","repository_url":"https://api.github.com/repos/hgrecco/pint","labels_url":"https://api.github.com/repos/hgrecco/pint/issues/461/labels{/name}","comments_url":"https://api.github.com/repos/hgrecco/pint/issues/461/comments","events_url":"https://api.github.com/repos/hgrecco/pint/issues/461/events","html_url":"https://github.com/hgrecco/pint/issues/461","id":190574846,"number":461,"title":"Measurement loses track of Variable derivatives","user":{"login":"tadhgmister","id":18615763,"avatar_url":"https://avatars.githubusercontent.com/u/18615763?v=3","gravatar_id":"","url":"https://api.github.com/users/tadhgmister","html_url":"https://github.com/tadhgmister","followers_url":"https://api.github.com/users/tadhgmister/followers","following_url":"https://api.github.com/users/tadhgmister/following{/other_user}","gists_url":"https://api.github.com/users/tadhgmister/gists{/gist_id}","starred_url":"https://api.github.com/users/tadhgmister/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tadhgmister/subscriptions","organizations_url":"https://api.github.com/users/tadhgmister/orgs","repos_url":"https://api.github.com/users/tadhgmister/repos","events_url":"https://api.github.com/users/tadhgmister/events{/privacy}","received_events_url":"https://api.github.com/users/tadhgmister/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-11-20T18:37:53Z","updated_at":"2016-11-20T19:12:37Z","closed_at":null,"body":"I have noticed that when doing arithmetic with Measurement objects it seems to lose the derivatives during calculations:\r\n```\r\nfrom uncertainties import ufloat as F\r\nimport pint\r\nureg = pint.UnitRegistry()\r\nM = ureg.Measurement\r\n\r\nm1, f1 = M(5,1),  F(5,1)\r\nm2, f2 = M(7,2), F(7,2)\r\nm3, f3 = m1*m2,  f1*f2\r\nprint(\"\"\"\\\r\nderivitives kept with pint:\r\n{m3.magnitude.derivatives}\r\n\r\nderivitives kept with ufloat:\r\n{f3.derivatives}\"\"\".format(m3=m3, f3=f3))\r\n```\r\nThe calculation with `ufloat` gives the derivatives essentially as `{f1:7, f2:5}`  however using `Measurement` instead gives  essentially `{<result of the calculation> : 1}`\r\n\r\nThis has been causing me some issues since it means that tracking [Correlated variables](https://pythonhosted.org/uncertainties/user_guide.html#correlated-variables) is does not work correctly, using the same example from their documentation:\r\n```\r\n>>> from pint import UnitRegistry\r\n>>> x = UnitRegistry().Measurement(0.2,0.01)\r\n>>> square = x**2\r\n>>> print(square)\r\n(0.040 +/- 0.004) dimensionless\r\n>>> square - x*x\r\n<Measurement(0.00, 0.01, dimensionless)>\r\n>>> y = x*x + 1\r\n>>> y-square\r\n<Measurement(1.00, 0.01, dimensionless)>\r\n```\r\nas you can see it doesn't detect that the last two prints should have `+/- 0`"},"comment":{"url":"https://api.github.com/repos/hgrecco/pint/issues/comments/261798175","html_url":"https://github.com/hgrecco/pint/issues/461#issuecomment-261798175","issue_url":"https://api.github.com/repos/hgrecco/pint/issues/461","id":261798175,"user":{"login":"tadhgmister","id":18615763,"avatar_url":"https://avatars.githubusercontent.com/u/18615763?v=3","gravatar_id":"","url":"https://api.github.com/users/tadhgmister","html_url":"https://github.com/tadhgmister","followers_url":"https://api.github.com/users/tadhgmister/followers","following_url":"https://api.github.com/users/tadhgmister/following{/other_user}","gists_url":"https://api.github.com/users/tadhgmister/gists{/gist_id}","starred_url":"https://api.github.com/users/tadhgmister/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tadhgmister/subscriptions","organizations_url":"https://api.github.com/users/tadhgmister/orgs","repos_url":"https://api.github.com/users/tadhgmister/repos","events_url":"https://api.github.com/users/tadhgmister/events{/privacy}","received_events_url":"https://api.github.com/users/tadhgmister/received_events","type":"User","site_admin":false},"created_at":"2016-11-20T19:12:37Z","updated_at":"2016-11-20T19:12:37Z","body":"It seems that `Quantity` does the calculation correctly when it's magnitude is a `ufloat`, did not preform an exhaustive test but it seems it will work for my purposes.\r\n\r\nit seems for my purposes changing `Measurement(value,error,unit)` to `Quantity(ufloat(value,error), unit)` caused the derivative propagation to correctly be tracked."}}
{"actor":{"display_login":"tadhgmister"}}