GitHub PullRequestReviewCommentEvent at 2014-07-19 14:32:52
Repository: scikit-learn
Actor: GaelVaroquaux
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/15143991","id":15143991,"diff_hunk":"@@ -175,6 +133,163 @@ def _num_samples(x):\n     return x.shape[0] if hasattr(x, 'shape') else len(x)\n \n \n+def check_consistent_length(*arrays):\n+    \"\"\"Check that all arrays have consistent first dimensions.\n+\n+    Checks whether all objects in arrays have the same shape or length.\n+\n+    Parameters\n+    ----------\n+    arrays : list or tuple of input objects.\n+        Objects that will be checked for consistent length.\n+    \"\"\"\n+\n+    n_samples = [_num_samples(X) for X in arrays if X is not None]\n+    uniques = np.unique(n_samples)\n+    if len(uniques) > 1:\n+        raise ValueError(\"Found arrays with inconsistent numbers of samples: %s\"\n+                         % str(uniques))\n+\n+\n+def _sparse_matrix_constructor(string_format):\n+    \"\"\"Get constructor from a sparse matrix string format.\"\"\"\n+    if string_format == \"csr\":\n+        return sp.csr_matrix\n+    elif string_format == \"csc\":\n+        return sp.csc_matrix\n+    elif string_format == \"coo\":\n+        return sp.coo_matrix\n+    else:\n+        raise ValueError(\"Don't know how to construct a sparse matrix of type\"\n+                         \" %s\" % string_format)\n+\n+\n+def _ensure_sparse_format(spmatrix, allowed_sparse, dtype, order, copy,\n+                          force_all_finite, convert_sparse_to):\n+    \"\"\"Convert a sparse matrix to a given format.\n+\n+    Checks the sparse format of spmatrix and converts if necessary.\n+\n+    Parameters\n+    ----------\n+    spmatrix : scipy sparse matrix.\n+        Input to validate and convert.\n+\n+    allowed_sparse : string or list of string, default=None\n+        String[s] representing allowed sparse matrix formats, such as 'csc',\n+        'csr', etc.  None means that sparse matrix input will raise an error.\n+        If the input is sparse but not in the allowed format, it will be\n+        converted to convert_sparse_to.\n+\n+    order : 'F', 'C' or None (default)\n+        Whether an array will be forced to be fortran or c-style.\n+\n+    copy : boolean, default=False\n+        Whether a forced copy will be triggered. If copy=False, a copy might\n+        be triggered by a conversion.\n+\n+    force_all_finite : boolean, default=True\n+        Whether to raise an error on np.inf and np.nan in X.\n+\n+    convert_sparse_to : string or None (default).\n+        Sparse format to convert sparse matrices to if allowed_sparse is not\n+        None.  By default, the first entry of allowed_sparse will be used.\n+\n+    Returns\n+    -------\n+    spmatrix_convertd : scipy sparse matrix.\n+        Matrix that is ensured to have an allowed type (or convert_sparse_to).\n+    \"\"\"\n+    if allowed_sparse is None:\n+        raise TypeError('A sparse matrix was passed, but dense '\n+                        'data is required. Use X.toarray() to '\n+                        'convert to a dense numpy array.')\n+    sparse_type = spmatrix.format\n+    if sparse_type in allowed_sparse:\n+        # correct type\n+        if dtype == spmatrix.dtype or dtype is None:\n+            # correct dtype\n+            if copy:\n+                spmatrix = spmatrix.copy()\n+        else:\n+            # convert dtype\n+            spmatrix = spmatrix.astype(dtype)\n+    else:\n+        # create new\n+        spmatrix = _sparse_matrix_constructor(convert_sparse_to)(","path":"sklearn/utils/validation.py","position":175,"original_position":176,"commit_id":"d03c84e5f8cb004f819b8d8b0d7203960fe50403","original_commit_id":"f72aa17939390c9fed104738cef3cccf00b76231","user":{"login":"GaelVaroquaux","id":208217,"avatar_url":"https://avatars.githubusercontent.com/u/208217?","gravatar_id":"5c9fb379c4e97b58960d74dcbfc5dee5","url":"https://api.github.com/users/GaelVaroquaux","html_url":"https://github.com/GaelVaroquaux","followers_url":"https://api.github.com/users/GaelVaroquaux/followers","following_url":"https://api.github.com/users/GaelVaroquaux/following{/other_user}","gists_url":"https://api.github.com/users/GaelVaroquaux/gists{/gist_id}","starred_url":"https://api.github.com/users/GaelVaroquaux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GaelVaroquaux/subscriptions","organizations_url":"https://api.github.com/users/GaelVaroquaux/orgs","repos_url":"https://api.github.com/users/GaelVaroquaux/repos","events_url":"https://api.github.com/users/GaelVaroquaux/events{/privacy}","received_events_url":"https://api.github.com/users/GaelVaroquaux/received_events","type":"User","site_admin":false},"body":"I think that here I would use the 'asformat' method of sparse matrices.","created_at":"2014-07-19T14:32:52Z","updated_at":"2014-07-19T14:32:52Z","html_url":"https://github.com/scikit-learn/scikit-learn/pull/3443#discussion_r15143991","pull_request_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3443","_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/15143991"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/3443#discussion_r15143991"},"pull_request":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3443"}}},"pull_request":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3443","id":18620541,"html_url":"https://github.com/scikit-learn/scikit-learn/pull/3443","diff_url":"https://github.com/scikit-learn/scikit-learn/pull/3443.diff","patch_url":"https://github.com/scikit-learn/scikit-learn/pull/3443.patch","issue_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/3443","number":3443,"state":"open","title":"[WIP] Input validation refactoring","user":{"login":"amueller","id":449558,"avatar_url":"https://avatars.githubusercontent.com/u/449558?","gravatar_id":"84f619d24e0f165f2ee36db34a911c4a","url":"https://api.github.com/users/amueller","html_url":"https://github.com/amueller","followers_url":"https://api.github.com/users/amueller/followers","following_url":"https://api.github.com/users/amueller/following{/other_user}","gists_url":"https://api.github.com/users/amueller/gists{/gist_id}","starred_url":"https://api.github.com/users/amueller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amueller/subscriptions","organizations_url":"https://api.github.com/users/amueller/orgs","repos_url":"https://api.github.com/users/amueller/repos","events_url":"https://api.github.com/users/amueller/events{/privacy}","received_events_url":"https://api.github.com/users/amueller/received_events","type":"User","site_admin":false},"body":"Refactor input validation to make it more consistent.\r\n\r\nTodo\r\n* [ ] Tests\r\n* [x] docstrings","created_at":"2014-07-19T13:00:24Z","updated_at":"2014-07-19T14:32:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4766056aa4250cabeebcf28939536d7968017040","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3443/commits","review_comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3443/comments","review_comment_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/{number}","comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/3443/comments","statuses_url":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/d03c84e5f8cb004f819b8d8b0d7203960fe50403","head":{"label":"amueller:input_validation_refactoring","ref":"input_validation_refactoring","sha":"d03c84e5f8cb004f819b8d8b0d7203960fe50403","user":{"login":"amueller","id":449558,"avatar_url":"https://avatars.githubusercontent.com/u/449558?","gravatar_id":"84f619d24e0f165f2ee36db34a911c4a","url":"https://api.github.com/users/amueller","html_url":"https://github.com/amueller","followers_url":"https://api.github.com/users/amueller/followers","following_url":"https://api.github.com/users/amueller/following{/other_user}","gists_url":"https://api.github.com/users/amueller/gists{/gist_id}","starred_url":"https://api.github.com/users/amueller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amueller/subscriptions","organizations_url":"https://api.github.com/users/amueller/orgs","repos_url":"https://api.github.com/users/amueller/repos","events_url":"https://api.github.com/users/amueller/events{/privacy}","received_events_url":"https://api.github.com/users/amueller/received_events","type":"User","site_admin":false},"repo":{"id":1622872,"name":"scikit-learn","full_name":"amueller/scikit-learn","owner":{"login":"amueller","id":449558,"avatar_url":"https://avatars.githubusercontent.com/u/449558?","gravatar_id":"84f619d24e0f165f2ee36db34a911c4a","url":"https://api.github.com/users/amueller","html_url":"https://github.com/amueller","followers_url":"https://api.github.com/users/amueller/followers","following_url":"https://api.github.com/users/amueller/following{/other_user}","gists_url":"https://api.github.com/users/amueller/gists{/gist_id}","starred_url":"https://api.github.com/users/amueller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amueller/subscriptions","organizations_url":"https://api.github.com/users/amueller/orgs","repos_url":"https://api.github.com/users/amueller/repos","events_url":"https://api.github.com/users/amueller/events{/privacy}","received_events_url":"https://api.github.com/users/amueller/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/amueller/scikit-learn","description":"scikit-learn main repo","fork":true,"url":"https://api.github.com/repos/amueller/scikit-learn","forks_url":"https://api.github.com/repos/amueller/scikit-learn/forks","keys_url":"https://api.github.com/repos/amueller/scikit-learn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/amueller/scikit-learn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/amueller/scikit-learn/teams","hooks_url":"https://api.github.com/repos/amueller/scikit-learn/hooks","issue_events_url":"https://api.github.com/repos/amueller/scikit-learn/issues/events{/number}","events_url":"https://api.github.com/repos/amueller/scikit-learn/events","assignees_url":"https://api.github.com/repos/amueller/scikit-learn/assignees{/user}","branches_url":"https://api.github.com/repos/amueller/scikit-learn/branches{/branch}","tags_url":"https://api.github.com/repos/amueller/scikit-learn/tags","blobs_url":"https://api.github.com/repos/amueller/scikit-learn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/amueller/scikit-learn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/amueller/scikit-learn/git/refs{/sha}","trees_url":"https://api.github.com/repos/amueller/scikit-learn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/amueller/scikit-learn/statuses/{sha}","languages_url":"https://api.github.com/repos/amueller/scikit-learn/languages","stargazers_url":"https://api.github.com/repos/amueller/scikit-learn/stargazers","contributors_url":"https://api.github.com/repos/amueller/scikit-learn/contributors","subscribers_url":"https://api.github.com/repos/amueller/scikit-learn/subscribers","subscription_url":"https://api.github.com/repos/amueller/scikit-learn/subscription","commits_url":"https://api.github.com/repos/amueller/scikit-learn/commits{/sha}","git_commits_url":"https://api.github.com/repos/amueller/scikit-learn/git/commits{/sha}","comments_url":"https://api.github.com/repos/amueller/scikit-learn/comments{/number}","issue_comment_url":"https://api.github.com/repos/amueller/scikit-learn/issues/comments/{number}","contents_url":"https://api.github.com/repos/amueller/scikit-learn/contents/{+path}","compare_url":"https://api.github.com/repos/amueller/scikit-learn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/amueller/scikit-learn/merges","archive_url":"https://api.github.com/repos/amueller/scikit-learn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/amueller/scikit-learn/downloads","issues_url":"https://api.github.com/repos/amueller/scikit-learn/issues{/number}","pulls_url":"https://api.github.com/repos/amueller/scikit-learn/pulls{/number}","milestones_url":"https://api.github.com/repos/amueller/scikit-learn/milestones{/number}","notifications_url":"https://api.github.com/repos/amueller/scikit-learn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/amueller/scikit-learn/labels{/name}","releases_url":"https://api.github.com/repos/amueller/scikit-learn/releases{/id}","created_at":"2011-04-16T12:41:21Z","updated_at":"2014-07-16T14:32:49Z","pushed_at":"2014-07-19T14:23:12Z","git_url":"git://github.com/amueller/scikit-learn.git","ssh_url":"git@github.com:amueller/scikit-learn.git","clone_url":"https://github.com/amueller/scikit-learn.git","svn_url":"https://github.com/amueller/scikit-learn","homepage":"http://scikit-learn.sourceforge.net","size":74894,"stargazers_count":5,"watchers_count":5,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"forks_count":2,"mirror_url":null,"open_issues_count":0,"forks":2,"open_issues":0,"watchers":5,"default_branch":"master"}},"base":{"label":"scikit-learn:master","ref":"master","sha":"4ec86301e2cfbaaa5fa23b4e36f5eba5ce8aa909","user":{"login":"scikit-learn","id":365630,"avatar_url":"https://avatars.githubusercontent.com/u/365630?","gravatar_id":"8a6ecb57b119c5a5b3d882d08a909278","url":"https://api.github.com/users/scikit-learn","html_url":"https://github.com/scikit-learn","followers_url":"https://api.github.com/users/scikit-learn/followers","following_url":"https://api.github.com/users/scikit-learn/following{/other_user}","gists_url":"https://api.github.com/users/scikit-learn/gists{/gist_id}","starred_url":"https://api.github.com/users/scikit-learn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scikit-learn/subscriptions","organizations_url":"https://api.github.com/users/scikit-learn/orgs","repos_url":"https://api.github.com/users/scikit-learn/repos","events_url":"https://api.github.com/users/scikit-learn/events{/privacy}","received_events_url":"https://api.github.com/users/scikit-learn/received_events","type":"Organization","site_admin":false},"repo":{"id":843222,"name":"scikit-learn","full_name":"scikit-learn/scikit-learn","owner":{"login":"scikit-learn","id":365630,"avatar_url":"https://avatars.githubusercontent.com/u/365630?","gravatar_id":"8a6ecb57b119c5a5b3d882d08a909278","url":"https://api.github.com/users/scikit-learn","html_url":"https://github.com/scikit-learn","followers_url":"https://api.github.com/users/scikit-learn/followers","following_url":"https://api.github.com/users/scikit-learn/following{/other_user}","gists_url":"https://api.github.com/users/scikit-learn/gists{/gist_id}","starred_url":"https://api.github.com/users/scikit-learn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scikit-learn/subscriptions","organizations_url":"https://api.github.com/users/scikit-learn/orgs","repos_url":"https://api.github.com/users/scikit-learn/repos","events_url":"https://api.github.com/users/scikit-learn/events{/privacy}","received_events_url":"https://api.github.com/users/scikit-learn/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/scikit-learn/scikit-learn","description":"scikit-learn: machine learning in Python","fork":false,"url":"https://api.github.com/repos/scikit-learn/scikit-learn","forks_url":"https://api.github.com/repos/scikit-learn/scikit-learn/forks","keys_url":"https://api.github.com/repos/scikit-learn/scikit-learn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/scikit-learn/scikit-learn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/scikit-learn/scikit-learn/teams","hooks_url":"https://api.github.com/repos/scikit-learn/scikit-learn/hooks","issue_events_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/events{/number}","events_url":"https://api.github.com/repos/scikit-learn/scikit-learn/events","assignees_url":"https://api.github.com/repos/scikit-learn/scikit-learn/assignees{/user}","branches_url":"https://api.github.com/repos/scikit-learn/scikit-learn/branches{/branch}","tags_url":"https://api.github.com/repos/scikit-learn/scikit-learn/tags","blobs_url":"https://api.github.com/repos/scikit-learn/scikit-learn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/scikit-learn/scikit-learn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/scikit-learn/scikit-learn/git/refs{/sha}","trees_url":"https://api.github.com/repos/scikit-learn/scikit-learn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/{sha}","languages_url":"https://api.github.com/repos/scikit-learn/scikit-learn/languages","stargazers_url":"https://api.github.com/repos/scikit-learn/scikit-learn/stargazers","contributors_url":"https://api.github.com/repos/scikit-learn/scikit-learn/contributors","subscribers_url":"https://api.github.com/repos/scikit-learn/scikit-learn/subscribers","subscription_url":"https://api.github.com/repos/scikit-learn/scikit-learn/subscription","commits_url":"https://api.github.com/repos/scikit-learn/scikit-learn/commits{/sha}","git_commits_url":"https://api.github.com/repos/scikit-learn/scikit-learn/git/commits{/sha}","comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/comments{/number}","issue_comment_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/comments/{number}","contents_url":"https://api.github.com/repos/scikit-learn/scikit-learn/contents/{+path}","compare_url":"https://api.github.com/repos/scikit-learn/scikit-learn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/scikit-learn/scikit-learn/merges","archive_url":"https://api.github.com/repos/scikit-learn/scikit-learn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/scikit-learn/scikit-learn/downloads","issues_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues{/number}","pulls_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls{/number}","milestones_url":"https://api.github.com/repos/scikit-learn/scikit-learn/milestones{/number}","notifications_url":"https://api.github.com/repos/scikit-learn/scikit-learn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/scikit-learn/scikit-learn/labels{/name}","releases_url":"https://api.github.com/repos/scikit-learn/scikit-learn/releases{/id}","created_at":"2010-08-17T09:43:38Z","updated_at":"2014-07-19T13:56:28Z","pushed_at":"2014-07-19T14:01:16Z","git_url":"git://github.com/scikit-learn/scikit-learn.git","ssh_url":"git@github.com:scikit-learn/scikit-learn.git","clone_url":"https://github.com/scikit-learn/scikit-learn.git","svn_url":"https://github.com/scikit-learn/scikit-learn","homepage":"http://scikit-learn.org","size":109676,"stargazers_count":3647,"watchers_count":3647,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":1927,"mirror_url":null,"open_issues_count":461,"forks":1927,"open_issues":461,"watchers":3647,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3443"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/3443"},"issue":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/3443"},"comments":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/3443/comments"},"review_comments":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3443/comments"},"review_comment":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3443/commits"},"statuses":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/d03c84e5f8cb004f819b8d8b0d7203960fe50403"}}}}