{"action":"created","comment":{"url":"https://api.github.com/repos/numpy/numpy/pulls/comments/30168717","id":30168717,"diff_hunk":"@@ -1921,36 +1951,80 @@ def cov(m, y=None, rowvar=1, bias=0, ddof=None):\n         y = np.asarray(y)\n         dtype = np.result_type(m, y, np.float64)\n     X = array(m, ndmin=2, dtype=dtype)\n+    if rowvar == 0 and X.shape[0] != 1:\n+        X = X.T\n+    if X.shape[0] == 0:\n+        return np.array([]).reshape(0, 0)\n+    if y is not None:\n+        y = array(y, copy=False, ndmin=2, dtype=dtype)\n+        if rowvar == 0 and y.shape[0] != 1:\n+            y = y.T\n+        X = np.vstack((X, y))\n \n-    if X.shape[0] == 1:\n-        rowvar = 1\n-    if rowvar:\n-        N = X.shape[1]\n-        axis = 0\n-    else:\n-        N = X.shape[0]\n-        axis = 1\n-\n-    # check ddof\n     if ddof is None:\n         if bias == 0:\n             ddof = 1\n         else:\n             ddof = 0\n-    fact = float(N - ddof)\n+\n+    # Get the product of frequencies and weights\n+    w = None\n+    if fweights is not None:\n+        fweights = np.asarray(fweights)\n+        if not np.all(fweights == np.around(fweights)):\n+            raise TypeError(\n+                \"fweights must be integer\")\n+        if fweights.ndim > 1:\n+            raise RuntimeError(\n+                \"cannot handle multidimensional fweights\")\n+        if fweights.shape[0] != X.shape[1]:\n+            raise RuntimeError(\n+                \"incompatible numbers of samples and fweights\")\n+        if any(fweights < 0):\n+            raise ValueError(\n+                \"fweights cannot be negative\")\n+        w = fweights.astype(np.float)\n+    if aweights is not None:\n+        aweights = np.asarray(aweights)\n+        if aweights.ndim > 1:\n+            raise RuntimeError(\n+                \"cannot handle multidimensional aweights\")\n+        if aweights.shape[0] != X.shape[1]:\n+            raise RuntimeError(\n+                \"incompatible numbers of samples and aweights\")\n+        if any(aweights < 0):\n+            raise ValueError(\n+                \"aweights cannot be negative\")\n+        aweights /= float(sum(aweights))\n+        if w is None:\n+            w = aweights\n+        else:\n+            w *= aweights\n+\n+    # Determine the normalization\n+    if w is None:\n+        fact = float(X.shape[1] - ddof)","path":"numpy/lib/function_base.py","position":165,"original_position":165,"commit_id":"2b2f3e2efdf53ec0ead90740e8548eecb6814014","original_commit_id":"2b2f3e2efdf53ec0ead90740e8548eecb6814014","user":{"login":"charris","id":77272,"avatar_url":"https://avatars.githubusercontent.com/u/77272?v=3","gravatar_id":"","url":"https://api.github.com/users/charris","html_url":"https://github.com/charris","followers_url":"https://api.github.com/users/charris/followers","following_url":"https://api.github.com/users/charris/following{/other_user}","gists_url":"https://api.github.com/users/charris/gists{/gist_id}","starred_url":"https://api.github.com/users/charris/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/charris/subscriptions","organizations_url":"https://api.github.com/users/charris/orgs","repos_url":"https://api.github.com/users/charris/repos","events_url":"https://api.github.com/users/charris/events{/privacy}","received_events_url":"https://api.github.com/users/charris/received_events","type":"User","site_admin":false},"body":"OK.","created_at":"2015-05-12T19:03:25Z","updated_at":"2015-05-12T19:03:25Z","html_url":"https://github.com/numpy/numpy/pull/4960#discussion_r30168717","pull_request_url":"https://api.github.com/repos/numpy/numpy/pulls/4960","_links":{"self":{"href":"https://api.github.com/repos/numpy/numpy/pulls/comments/30168717"},"html":{"href":"https://github.com/numpy/numpy/pull/4960#discussion_r30168717"},"pull_request":{"href":"https://api.github.com/repos/numpy/numpy/pulls/4960"}}},"pull_request":{"url":"https://api.github.com/repos/numpy/numpy/pulls/4960","id":19720596,"html_url":"https://github.com/numpy/numpy/pull/4960","diff_url":"https://github.com/numpy/numpy/pull/4960.diff","patch_url":"https://github.com/numpy/numpy/pull/4960.patch","issue_url":"https://api.github.com/repos/numpy/numpy/issues/4960","number":4960,"state":"open","locked":false,"title":"ENH: add a weighted covariance calculation.","user":{"login":"tpoole","id":872729,"avatar_url":"https://avatars.githubusercontent.com/u/872729?v=3","gravatar_id":"","url":"https://api.github.com/users/tpoole","html_url":"https://github.com/tpoole","followers_url":"https://api.github.com/users/tpoole/followers","following_url":"https://api.github.com/users/tpoole/following{/other_user}","gists_url":"https://api.github.com/users/tpoole/gists{/gist_id}","starred_url":"https://api.github.com/users/tpoole/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tpoole/subscriptions","organizations_url":"https://api.github.com/users/tpoole/orgs","repos_url":"https://api.github.com/users/tpoole/repos","events_url":"https://api.github.com/users/tpoole/events{/privacy}","received_events_url":"https://api.github.com/users/tpoole/received_events","type":"User","site_admin":false},"body":"Weights can now be included in a covariance calculation in a similar manner as\r\nthe existing implementation of a weighted average.","created_at":"2014-08-13T12:25:29Z","updated_at":"2015-05-12T19:03:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d850f84d5a338dabcd41b5ebe6f920e5fec6ab33","assignee":null,"milestone":{"url":"https://api.github.com/repos/numpy/numpy/milestones/35","html_url":"https://github.com/numpy/numpy/milestones/1.10.0%20release","labels_url":"https://api.github.com/repos/numpy/numpy/milestones/35/labels","id":1055363,"number":35,"title":"1.10.0 release","description":"Marker for PRs that should go into Numpy 1.10.1.","creator":{"login":"charris","id":77272,"avatar_url":"https://avatars.githubusercontent.com/u/77272?v=3","gravatar_id":"","url":"https://api.github.com/users/charris","html_url":"https://github.com/charris","followers_url":"https://api.github.com/users/charris/followers","following_url":"https://api.github.com/users/charris/following{/other_user}","gists_url":"https://api.github.com/users/charris/gists{/gist_id}","starred_url":"https://api.github.com/users/charris/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/charris/subscriptions","organizations_url":"https://api.github.com/users/charris/orgs","repos_url":"https://api.github.com/users/charris/repos","events_url":"https://api.github.com/users/charris/events{/privacy}","received_events_url":"https://api.github.com/users/charris/received_events","type":"User","site_admin":false},"open_issues":16,"closed_issues":24,"state":"open","created_at":"2015-04-07T00:02:10Z","updated_at":"2015-05-12T04:43:16Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/numpy/numpy/pulls/4960/commits","review_comments_url":"https://api.github.com/repos/numpy/numpy/pulls/4960/comments","review_comment_url":"https://api.github.com/repos/numpy/numpy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/numpy/numpy/issues/4960/comments","statuses_url":"https://api.github.com/repos/numpy/numpy/statuses/2b2f3e2efdf53ec0ead90740e8548eecb6814014","head":{"label":"tpoole:weighted_cov","ref":"weighted_cov","sha":"2b2f3e2efdf53ec0ead90740e8548eecb6814014","user":{"login":"tpoole","id":872729,"avatar_url":"https://avatars.githubusercontent.com/u/872729?v=3","gravatar_id":"","url":"https://api.github.com/users/tpoole","html_url":"https://github.com/tpoole","followers_url":"https://api.github.com/users/tpoole/followers","following_url":"https://api.github.com/users/tpoole/following{/other_user}","gists_url":"https://api.github.com/users/tpoole/gists{/gist_id}","starred_url":"https://api.github.com/users/tpoole/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tpoole/subscriptions","organizations_url":"https://api.github.com/users/tpoole/orgs","repos_url":"https://api.github.com/users/tpoole/repos","events_url":"https://api.github.com/users/tpoole/events{/privacy}","received_events_url":"https://api.github.com/users/tpoole/received_events","type":"User","site_admin":false},"repo":{"id":22914427,"name":"numpy","full_name":"tpoole/numpy","owner":{"login":"tpoole","id":872729,"avatar_url":"https://avatars.githubusercontent.com/u/872729?v=3","gravatar_id":"","url":"https://api.github.com/users/tpoole","html_url":"https://github.com/tpoole","followers_url":"https://api.github.com/users/tpoole/followers","following_url":"https://api.github.com/users/tpoole/following{/other_user}","gists_url":"https://api.github.com/users/tpoole/gists{/gist_id}","starred_url":"https://api.github.com/users/tpoole/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tpoole/subscriptions","organizations_url":"https://api.github.com/users/tpoole/orgs","repos_url":"https://api.github.com/users/tpoole/repos","events_url":"https://api.github.com/users/tpoole/events{/privacy}","received_events_url":"https://api.github.com/users/tpoole/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tpoole/numpy","description":"Numpy main repository","fork":true,"url":"https://api.github.com/repos/tpoole/numpy","forks_url":"https://api.github.com/repos/tpoole/numpy/forks","keys_url":"https://api.github.com/repos/tpoole/numpy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tpoole/numpy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tpoole/numpy/teams","hooks_url":"https://api.github.com/repos/tpoole/numpy/hooks","issue_events_url":"https://api.github.com/repos/tpoole/numpy/issues/events{/number}","events_url":"https://api.github.com/repos/tpoole/numpy/events","assignees_url":"https://api.github.com/repos/tpoole/numpy/assignees{/user}","branches_url":"https://api.github.com/repos/tpoole/numpy/branches{/branch}","tags_url":"https://api.github.com/repos/tpoole/numpy/tags","blobs_url":"https://api.github.com/repos/tpoole/numpy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tpoole/numpy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tpoole/numpy/git/refs{/sha}","trees_url":"https://api.github.com/repos/tpoole/numpy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tpoole/numpy/statuses/{sha}","languages_url":"https://api.github.com/repos/tpoole/numpy/languages","stargazers_url":"https://api.github.com/repos/tpoole/numpy/stargazers","contributors_url":"https://api.github.com/repos/tpoole/numpy/contributors","subscribers_url":"https://api.github.com/repos/tpoole/numpy/subscribers","subscription_url":"https://api.github.com/repos/tpoole/numpy/subscription","commits_url":"https://api.github.com/repos/tpoole/numpy/commits{/sha}","git_commits_url":"https://api.github.com/repos/tpoole/numpy/git/commits{/sha}","comments_url":"https://api.github.com/repos/tpoole/numpy/comments{/number}","issue_comment_url":"https://api.github.com/repos/tpoole/numpy/issues/comments{/number}","contents_url":"https://api.github.com/repos/tpoole/numpy/contents/{+path}","compare_url":"https://api.github.com/repos/tpoole/numpy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tpoole/numpy/merges","archive_url":"https://api.github.com/repos/tpoole/numpy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tpoole/numpy/downloads","issues_url":"https://api.github.com/repos/tpoole/numpy/issues{/number}","pulls_url":"https://api.github.com/repos/tpoole/numpy/pulls{/number}","milestones_url":"https://api.github.com/repos/tpoole/numpy/milestones{/number}","notifications_url":"https://api.github.com/repos/tpoole/numpy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tpoole/numpy/labels{/name}","releases_url":"https://api.github.com/repos/tpoole/numpy/releases{/id}","created_at":"2014-08-13T12:16:15Z","updated_at":"2015-05-08T18:56:29Z","pushed_at":"2015-05-10T11:46:05Z","git_url":"git://github.com/tpoole/numpy.git","ssh_url":"git@github.com:tpoole/numpy.git","clone_url":"https://github.com/tpoole/numpy.git","svn_url":"https://github.com/tpoole/numpy","homepage":"http://www.numpy.org/","size":39005,"stargazers_count":0,"watchers_count":0,"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":0,"default_branch":"master"}},"base":{"label":"numpy:master","ref":"master","sha":"30e3d41b6d11c18e17eb283a61bbe9bbf4bb4d8f","user":{"login":"numpy","id":288276,"avatar_url":"https://avatars.githubusercontent.com/u/288276?v=3","gravatar_id":"","url":"https://api.github.com/users/numpy","html_url":"https://github.com/numpy","followers_url":"https://api.github.com/users/numpy/followers","following_url":"https://api.github.com/users/numpy/following{/other_user}","gists_url":"https://api.github.com/users/numpy/gists{/gist_id}","starred_url":"https://api.github.com/users/numpy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/numpy/subscriptions","organizations_url":"https://api.github.com/users/numpy/orgs","repos_url":"https://api.github.com/users/numpy/repos","events_url":"https://api.github.com/users/numpy/events{/privacy}","received_events_url":"https://api.github.com/users/numpy/received_events","type":"Organization","site_admin":false},"repo":{"id":908607,"name":"numpy","full_name":"numpy/numpy","owner":{"login":"numpy","id":288276,"avatar_url":"https://avatars.githubusercontent.com/u/288276?v=3","gravatar_id":"","url":"https://api.github.com/users/numpy","html_url":"https://github.com/numpy","followers_url":"https://api.github.com/users/numpy/followers","following_url":"https://api.github.com/users/numpy/following{/other_user}","gists_url":"https://api.github.com/users/numpy/gists{/gist_id}","starred_url":"https://api.github.com/users/numpy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/numpy/subscriptions","organizations_url":"https://api.github.com/users/numpy/orgs","repos_url":"https://api.github.com/users/numpy/repos","events_url":"https://api.github.com/users/numpy/events{/privacy}","received_events_url":"https://api.github.com/users/numpy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/numpy/numpy","description":"Numpy main repository","fork":false,"url":"https://api.github.com/repos/numpy/numpy","forks_url":"https://api.github.com/repos/numpy/numpy/forks","keys_url":"https://api.github.com/repos/numpy/numpy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/numpy/numpy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/numpy/numpy/teams","hooks_url":"https://api.github.com/repos/numpy/numpy/hooks","issue_events_url":"https://api.github.com/repos/numpy/numpy/issues/events{/number}","events_url":"https://api.github.com/repos/numpy/numpy/events","assignees_url":"https://api.github.com/repos/numpy/numpy/assignees{/user}","branches_url":"https://api.github.com/repos/numpy/numpy/branches{/branch}","tags_url":"https://api.github.com/repos/numpy/numpy/tags","blobs_url":"https://api.github.com/repos/numpy/numpy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/numpy/numpy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/numpy/numpy/git/refs{/sha}","trees_url":"https://api.github.com/repos/numpy/numpy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/numpy/numpy/statuses/{sha}","languages_url":"https://api.github.com/repos/numpy/numpy/languages","stargazers_url":"https://api.github.com/repos/numpy/numpy/stargazers","contributors_url":"https://api.github.com/repos/numpy/numpy/contributors","subscribers_url":"https://api.github.com/repos/numpy/numpy/subscribers","subscription_url":"https://api.github.com/repos/numpy/numpy/subscription","commits_url":"https://api.github.com/repos/numpy/numpy/commits{/sha}","git_commits_url":"https://api.github.com/repos/numpy/numpy/git/commits{/sha}","comments_url":"https://api.github.com/repos/numpy/numpy/comments{/number}","issue_comment_url":"https://api.github.com/repos/numpy/numpy/issues/comments{/number}","contents_url":"https://api.github.com/repos/numpy/numpy/contents/{+path}","compare_url":"https://api.github.com/repos/numpy/numpy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/numpy/numpy/merges","archive_url":"https://api.github.com/repos/numpy/numpy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/numpy/numpy/downloads","issues_url":"https://api.github.com/repos/numpy/numpy/issues{/number}","pulls_url":"https://api.github.com/repos/numpy/numpy/pulls{/number}","milestones_url":"https://api.github.com/repos/numpy/numpy/milestones{/number}","notifications_url":"https://api.github.com/repos/numpy/numpy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/numpy/numpy/labels{/name}","releases_url":"https://api.github.com/repos/numpy/numpy/releases{/id}","created_at":"2010-09-13T23:02:39Z","updated_at":"2015-05-12T17:16:44Z","pushed_at":"2015-05-12T08:37:54Z","git_url":"git://github.com/numpy/numpy.git","ssh_url":"git@github.com:numpy/numpy.git","clone_url":"https://github.com/numpy/numpy.git","svn_url":"https://github.com/numpy/numpy","homepage":"http://www.numpy.org/","size":65537,"stargazers_count":1917,"watchers_count":1917,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":982,"mirror_url":null,"open_issues_count":854,"forks":982,"open_issues":854,"watchers":1917,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/numpy/numpy/pulls/4960"},"html":{"href":"https://github.com/numpy/numpy/pull/4960"},"issue":{"href":"https://api.github.com/repos/numpy/numpy/issues/4960"},"comments":{"href":"https://api.github.com/repos/numpy/numpy/issues/4960/comments"},"review_comments":{"href":"https://api.github.com/repos/numpy/numpy/pulls/4960/comments"},"review_comment":{"href":"https://api.github.com/repos/numpy/numpy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/numpy/numpy/pulls/4960/commits"},"statuses":{"href":"https://api.github.com/repos/numpy/numpy/statuses/2b2f3e2efdf53ec0ead90740e8548eecb6814014"}}}}