{"action":"created","comment":{"url":"https://api.github.com/repos/astropy/astropy/pulls/comments/53553419","id":53553419,"diff_hunk":"@@ -0,0 +1,538 @@\n+# Licensed under a 3-clause BSD style license - see LICENSE.rst\n+\n+\"\"\"\n+Tests that relate to evaluating models with quantity parameters\n+\"\"\"\n+\n+from __future__ import (absolute_import, unicode_literals, division,\n+                        print_function)\n+\n+from numpy.testing import assert_allclose\n+\n+\n+from ..core import Fittable1DModel\n+from ..parameters import Parameter\n+from ..models import Gaussian1D\n+from ... import units as u\n+from ...units import UnitsError\n+from ...tests.helper import pytest, assert_quantity_allclose\n+\n+\n+# We start off by taking some simple cases where the units are defined by\n+# whatever the model is initialized with, and we check that the model evaluation\n+# returns quantities.\n+\n+\n+@pytest.mark.xfail\n+def test_evaluate_with_quantities():\n+    \"\"\"\n+    Test evaluation of a single model with Quantity parameters that do\n+    not explicitly require units.\n+    \"\"\"\n+\n+    # We create two models here - one with quantities, and one without. The one\n+    # without is used to create the reference values for comparison.\n+\n+    g = Gaussian1D(1, 1, 0.1)\n+    gq = Gaussian1D(1 * u.J, 1 * u.m, 0.1 * u.m)\n+\n+    # We first check that calling the Gaussian with quantities returns the\n+    # expected result\n+    assert_quantity_allclose(gq(1 * u.m), g(1) * u.J)\n+\n+    # Units have to be specified for the Gaussian with quantities - if not, an\n+    # error is raised\n+    with pytest.raises(UnitsError) as exc:\n+        gq(1)\n+    assert exc.value.args[0] == (\"Units of input 'x', (dimensionless), could not be \"\n+                                 \"converted to required input units of m (length)\")\n+\n+    # However, zero is a special case\n+    assert_quantity_allclose(gq(0), g(0) * u.J)\n+\n+    # We can also evaluate models with equivalent units\n+    assert_allclose(gq(0.0005 * u.km).value, g(0.5))\n+\n+    # But not with incompatible units\n+    with pytest.raises(UnitsError) as exc:\n+        gq(3 * u.s)\n+    assert exc.value.args[0] == (\"Units of input 'x', s (time), could not be \"\n+                                 \"converted to required input units of m (length)\")\n+\n+    # We also can't evaluate the model without quantities with a quantity\n+    with pytest.raises(UnitsError) as exc:\n+        g(3 * u.m)\n+    assert exc.value.args[0] == (\"Input in m (length), could not be converted \"\n+                                 \"to required to dimensionless input\")","path":"astropy/modeling/tests/test_quantities_evaluation.py","position":66,"original_position":66,"commit_id":"13453ea7288e87f7d7e78f0fd656ad60d033fcff","original_commit_id":"13453ea7288e87f7d7e78f0fd656ad60d033fcff","user":{"login":"mhvk","id":2789820,"avatar_url":"https://avatars.githubusercontent.com/u/2789820?v=3","gravatar_id":"","url":"https://api.github.com/users/mhvk","html_url":"https://github.com/mhvk","followers_url":"https://api.github.com/users/mhvk/followers","following_url":"https://api.github.com/users/mhvk/following{/other_user}","gists_url":"https://api.github.com/users/mhvk/gists{/gist_id}","starred_url":"https://api.github.com/users/mhvk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhvk/subscriptions","organizations_url":"https://api.github.com/users/mhvk/orgs","repos_url":"https://api.github.com/users/mhvk/repos","events_url":"https://api.github.com/users/mhvk/events{/privacy}","received_events_url":"https://api.github.com/users/mhvk/received_events","type":"User","site_admin":false},"body":"Agreed that as much as possible one should make code duck-type whether something has a unit or not.\r\n(wish I had more time to comment fully, but this comment stood out as one where the API may be more bothersome than needed).","created_at":"2016-02-20T16:56:14Z","updated_at":"2016-02-20T16:56:14Z","html_url":"https://github.com/astropy/astropy/pull/4615#discussion_r53553419","pull_request_url":"https://api.github.com/repos/astropy/astropy/pulls/4615","_links":{"self":{"href":"https://api.github.com/repos/astropy/astropy/pulls/comments/53553419"},"html":{"href":"https://github.com/astropy/astropy/pull/4615#discussion_r53553419"},"pull_request":{"href":"https://api.github.com/repos/astropy/astropy/pulls/4615"}}},"pull_request":{"url":"https://api.github.com/repos/astropy/astropy/pulls/4615","id":59828208,"html_url":"https://github.com/astropy/astropy/pull/4615","diff_url":"https://github.com/astropy/astropy/pull/4615.diff","patch_url":"https://github.com/astropy/astropy/pull/4615.patch","issue_url":"https://api.github.com/repos/astropy/astropy/issues/4615","number":4615,"state":"open","locked":false,"title":"Quantity Support in Modeling [continued]","user":{"login":"astrofrog","id":314716,"avatar_url":"https://avatars.githubusercontent.com/u/314716?v=3","gravatar_id":"","url":"https://api.github.com/users/astrofrog","html_url":"https://github.com/astrofrog","followers_url":"https://api.github.com/users/astrofrog/followers","following_url":"https://api.github.com/users/astrofrog/following{/other_user}","gists_url":"https://api.github.com/users/astrofrog/gists{/gist_id}","starred_url":"https://api.github.com/users/astrofrog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/astrofrog/subscriptions","organizations_url":"https://api.github.com/users/astrofrog/orgs","repos_url":"https://api.github.com/users/astrofrog/repos","events_url":"https://api.github.com/users/astrofrog/events{/privacy}","received_events_url":"https://api.github.com/users/astrofrog/received_events","type":"User","site_admin":false},"body":"### Read me first!\r\n\r\nThis is a rebased continuation of @embray's https://github.com/astropy/astropy/pull/3852, and is still a work in progress, but I'll be pushing from time to time to make sure the CI doesn't break.\r\n\r\n**At this stage please only review the tests, which show a proposed API - do not comment on implementation (which is incomplete)**\r\n\r\nTo-dos (some to-do list items are taken from @embray's list) - not all have to be done for this PR\r\n\r\n* [ ] Support compound model/model arithmetic (check that units match/are equivalent)\r\n* [ ] More sophisticated unit specs for parameters\r\n* [ ] Ability to override ``input_units``/``output_units`` per instance\r\n* [ ] Should we take into account all active equivalencies at model creation time?\r\n* [ ] Implement more unit specs on built-in models\r\n* [ ] Remove getter/setter attributes of ``Parameter``? (see #3852)\r\n* [ ] Implement @mhvk's comments from #3852\r\n* [ ] Support for fitting","created_at":"2016-02-18T16:50:16Z","updated_at":"2016-02-20T16:56:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3b4d5f7ad83fcb7e9d557777bbf19f0426018f5f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/astropy/astropy/pulls/4615/commits","review_comments_url":"https://api.github.com/repos/astropy/astropy/pulls/4615/comments","review_comment_url":"https://api.github.com/repos/astropy/astropy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/astropy/astropy/issues/4615/comments","statuses_url":"https://api.github.com/repos/astropy/astropy/statuses/13453ea7288e87f7d7e78f0fd656ad60d033fcff","head":{"label":"astrofrog:modeling-units","ref":"modeling-units","sha":"13453ea7288e87f7d7e78f0fd656ad60d033fcff","user":{"login":"astrofrog","id":314716,"avatar_url":"https://avatars.githubusercontent.com/u/314716?v=3","gravatar_id":"","url":"https://api.github.com/users/astrofrog","html_url":"https://github.com/astrofrog","followers_url":"https://api.github.com/users/astrofrog/followers","following_url":"https://api.github.com/users/astrofrog/following{/other_user}","gists_url":"https://api.github.com/users/astrofrog/gists{/gist_id}","starred_url":"https://api.github.com/users/astrofrog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/astrofrog/subscriptions","organizations_url":"https://api.github.com/users/astrofrog/orgs","repos_url":"https://api.github.com/users/astrofrog/repos","events_url":"https://api.github.com/users/astrofrog/events{/privacy}","received_events_url":"https://api.github.com/users/astrofrog/received_events","type":"User","site_admin":false},"repo":{"id":2576841,"name":"astropy","full_name":"astrofrog/astropy","owner":{"login":"astrofrog","id":314716,"avatar_url":"https://avatars.githubusercontent.com/u/314716?v=3","gravatar_id":"","url":"https://api.github.com/users/astrofrog","html_url":"https://github.com/astrofrog","followers_url":"https://api.github.com/users/astrofrog/followers","following_url":"https://api.github.com/users/astrofrog/following{/other_user}","gists_url":"https://api.github.com/users/astrofrog/gists{/gist_id}","starred_url":"https://api.github.com/users/astrofrog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/astrofrog/subscriptions","organizations_url":"https://api.github.com/users/astrofrog/orgs","repos_url":"https://api.github.com/users/astrofrog/repos","events_url":"https://api.github.com/users/astrofrog/events{/privacy}","received_events_url":"https://api.github.com/users/astrofrog/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/astrofrog/astropy","description":"Main AstroPy repository","fork":true,"url":"https://api.github.com/repos/astrofrog/astropy","forks_url":"https://api.github.com/repos/astrofrog/astropy/forks","keys_url":"https://api.github.com/repos/astrofrog/astropy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/astrofrog/astropy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/astrofrog/astropy/teams","hooks_url":"https://api.github.com/repos/astrofrog/astropy/hooks","issue_events_url":"https://api.github.com/repos/astrofrog/astropy/issues/events{/number}","events_url":"https://api.github.com/repos/astrofrog/astropy/events","assignees_url":"https://api.github.com/repos/astrofrog/astropy/assignees{/user}","branches_url":"https://api.github.com/repos/astrofrog/astropy/branches{/branch}","tags_url":"https://api.github.com/repos/astrofrog/astropy/tags","blobs_url":"https://api.github.com/repos/astrofrog/astropy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/astrofrog/astropy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/astrofrog/astropy/git/refs{/sha}","trees_url":"https://api.github.com/repos/astrofrog/astropy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/astrofrog/astropy/statuses/{sha}","languages_url":"https://api.github.com/repos/astrofrog/astropy/languages","stargazers_url":"https://api.github.com/repos/astrofrog/astropy/stargazers","contributors_url":"https://api.github.com/repos/astrofrog/astropy/contributors","subscribers_url":"https://api.github.com/repos/astrofrog/astropy/subscribers","subscription_url":"https://api.github.com/repos/astrofrog/astropy/subscription","commits_url":"https://api.github.com/repos/astrofrog/astropy/commits{/sha}","git_commits_url":"https://api.github.com/repos/astrofrog/astropy/git/commits{/sha}","comments_url":"https://api.github.com/repos/astrofrog/astropy/comments{/number}","issue_comment_url":"https://api.github.com/repos/astrofrog/astropy/issues/comments{/number}","contents_url":"https://api.github.com/repos/astrofrog/astropy/contents/{+path}","compare_url":"https://api.github.com/repos/astrofrog/astropy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/astrofrog/astropy/merges","archive_url":"https://api.github.com/repos/astrofrog/astropy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/astrofrog/astropy/downloads","issues_url":"https://api.github.com/repos/astrofrog/astropy/issues{/number}","pulls_url":"https://api.github.com/repos/astrofrog/astropy/pulls{/number}","milestones_url":"https://api.github.com/repos/astrofrog/astropy/milestones{/number}","notifications_url":"https://api.github.com/repos/astrofrog/astropy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/astrofrog/astropy/labels{/name}","releases_url":"https://api.github.com/repos/astrofrog/astropy/releases{/id}","deployments_url":"https://api.github.com/repos/astrofrog/astropy/deployments","created_at":"2011-10-14T14:58:26Z","updated_at":"2014-06-22T14:17:33Z","pushed_at":"2016-02-20T11:09:05Z","git_url":"git://github.com/astrofrog/astropy.git","ssh_url":"git@github.com:astrofrog/astropy.git","clone_url":"https://github.com/astrofrog/astropy.git","svn_url":"https://github.com/astrofrog/astropy","homepage":"astropy.org","size":41187,"stargazers_count":4,"watchers_count":4,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":4,"default_branch":"master"}},"base":{"label":"astropy:master","ref":"master","sha":"97a6d30f2171eb406818449a4dcc2022a2b00823","user":{"login":"astropy","id":847984,"avatar_url":"https://avatars.githubusercontent.com/u/847984?v=3","gravatar_id":"","url":"https://api.github.com/users/astropy","html_url":"https://github.com/astropy","followers_url":"https://api.github.com/users/astropy/followers","following_url":"https://api.github.com/users/astropy/following{/other_user}","gists_url":"https://api.github.com/users/astropy/gists{/gist_id}","starred_url":"https://api.github.com/users/astropy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/astropy/subscriptions","organizations_url":"https://api.github.com/users/astropy/orgs","repos_url":"https://api.github.com/users/astropy/repos","events_url":"https://api.github.com/users/astropy/events{/privacy}","received_events_url":"https://api.github.com/users/astropy/received_events","type":"Organization","site_admin":false},"repo":{"id":2081289,"name":"astropy","full_name":"astropy/astropy","owner":{"login":"astropy","id":847984,"avatar_url":"https://avatars.githubusercontent.com/u/847984?v=3","gravatar_id":"","url":"https://api.github.com/users/astropy","html_url":"https://github.com/astropy","followers_url":"https://api.github.com/users/astropy/followers","following_url":"https://api.github.com/users/astropy/following{/other_user}","gists_url":"https://api.github.com/users/astropy/gists{/gist_id}","starred_url":"https://api.github.com/users/astropy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/astropy/subscriptions","organizations_url":"https://api.github.com/users/astropy/orgs","repos_url":"https://api.github.com/users/astropy/repos","events_url":"https://api.github.com/users/astropy/events{/privacy}","received_events_url":"https://api.github.com/users/astropy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/astropy/astropy","description":"Repository for the Astropy core package","fork":false,"url":"https://api.github.com/repos/astropy/astropy","forks_url":"https://api.github.com/repos/astropy/astropy/forks","keys_url":"https://api.github.com/repos/astropy/astropy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/astropy/astropy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/astropy/astropy/teams","hooks_url":"https://api.github.com/repos/astropy/astropy/hooks","issue_events_url":"https://api.github.com/repos/astropy/astropy/issues/events{/number}","events_url":"https://api.github.com/repos/astropy/astropy/events","assignees_url":"https://api.github.com/repos/astropy/astropy/assignees{/user}","branches_url":"https://api.github.com/repos/astropy/astropy/branches{/branch}","tags_url":"https://api.github.com/repos/astropy/astropy/tags","blobs_url":"https://api.github.com/repos/astropy/astropy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/astropy/astropy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/astropy/astropy/git/refs{/sha}","trees_url":"https://api.github.com/repos/astropy/astropy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/astropy/astropy/statuses/{sha}","languages_url":"https://api.github.com/repos/astropy/astropy/languages","stargazers_url":"https://api.github.com/repos/astropy/astropy/stargazers","contributors_url":"https://api.github.com/repos/astropy/astropy/contributors","subscribers_url":"https://api.github.com/repos/astropy/astropy/subscribers","subscription_url":"https://api.github.com/repos/astropy/astropy/subscription","commits_url":"https://api.github.com/repos/astropy/astropy/commits{/sha}","git_commits_url":"https://api.github.com/repos/astropy/astropy/git/commits{/sha}","comments_url":"https://api.github.com/repos/astropy/astropy/comments{/number}","issue_comment_url":"https://api.github.com/repos/astropy/astropy/issues/comments{/number}","contents_url":"https://api.github.com/repos/astropy/astropy/contents/{+path}","compare_url":"https://api.github.com/repos/astropy/astropy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/astropy/astropy/merges","archive_url":"https://api.github.com/repos/astropy/astropy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/astropy/astropy/downloads","issues_url":"https://api.github.com/repos/astropy/astropy/issues{/number}","pulls_url":"https://api.github.com/repos/astropy/astropy/pulls{/number}","milestones_url":"https://api.github.com/repos/astropy/astropy/milestones{/number}","notifications_url":"https://api.github.com/repos/astropy/astropy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/astropy/astropy/labels{/name}","releases_url":"https://api.github.com/repos/astropy/astropy/releases{/id}","deployments_url":"https://api.github.com/repos/astropy/astropy/deployments","created_at":"2011-07-21T01:33:49Z","updated_at":"2016-02-20T13:33:46Z","pushed_at":"2016-02-20T14:17:28Z","git_url":"git://github.com/astropy/astropy.git","ssh_url":"git@github.com:astropy/astropy.git","clone_url":"https://github.com/astropy/astropy.git","svn_url":"https://github.com/astropy/astropy","homepage":"www.astropy.org","size":60099,"stargazers_count":796,"watchers_count":796,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":506,"mirror_url":null,"open_issues_count":679,"forks":506,"open_issues":679,"watchers":796,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/astropy/astropy/pulls/4615"},"html":{"href":"https://github.com/astropy/astropy/pull/4615"},"issue":{"href":"https://api.github.com/repos/astropy/astropy/issues/4615"},"comments":{"href":"https://api.github.com/repos/astropy/astropy/issues/4615/comments"},"review_comments":{"href":"https://api.github.com/repos/astropy/astropy/pulls/4615/comments"},"review_comment":{"href":"https://api.github.com/repos/astropy/astropy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/astropy/astropy/pulls/4615/commits"},"statuses":{"href":"https://api.github.com/repos/astropy/astropy/statuses/13453ea7288e87f7d7e78f0fd656ad60d033fcff"}}}}