{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/174576552","pull_request_review_id":103958474,"id":174576552,"diff_hunk":"@@ -640,6 +640,33 @@ def test_count_vectorizer_with_binary(self):\n             feature, expected = r\n             self.assertEqual(feature, expected)\n \n+    def test_count_vectorizer_from_vocab(self):\n+        model = CountVectorizerModel.from_vocabulary([\"a\", \"b\", \"c\"], inputCol=\"words\",\n+                                                     outputCol=\"features\", minTF=2)\n+        self.assertEqual(model.vocabulary, [\"a\", \"b\", \"c\"])\n+        self.assertEqual(model.getMinTF(), 2)\n+\n+        dataset = self.spark.createDataFrame([\n+            (0, \"a a a b b c\".split(' '), SparseVector(3, {0: 3.0, 1: 2.0}),),\n+            (1, \"a a\".split(' '), SparseVector(3, {0: 2.0}),),\n+            (2, \"a b\".split(' '), SparseVector(3, {}),)], [\"id\", \"words\", \"expected\"])\n+\n+        transformed_list = model.transform(dataset).select(\"features\", \"expected\").collect()\n+\n+        for r in transformed_list:\n+            feature, expected = r\n+            self.assertEqual(feature, expected)\n+\n+        # Test an empty vocabulary\n+        with QuietTest(self.sc):\n+            with self.assertRaisesRegexp(Exception, \"vocabSize.*invalid.*0\"):\n+                CountVectorizerModel.from_vocabulary([], inputCol=\"words\")\n+\n+        # Test model with default settings can transform\n+        model_default = CountVectorizerModel.from_vocabulary([\"a\", \"b\", \"c\"], inputCol=\"words\")\n+        transformed_list = model_default.transform(dataset).collect()\n+        self.assertEqual(len(transformed_list), 3)","path":"python/pyspark/ml/tests.py","position":29,"original_position":29,"commit_id":"5220ff131deb6914ee0b899d9c95a2861f057d55","original_commit_id":"5220ff131deb6914ee0b899d9c95a2861f057d55","user":{"login":"BryanCutler","id":4534389,"avatar_url":"https://avatars3.githubusercontent.com/u/4534389?v=4","gravatar_id":"","url":"https://api.github.com/users/BryanCutler","html_url":"https://github.com/BryanCutler","followers_url":"https://api.github.com/users/BryanCutler/followers","following_url":"https://api.github.com/users/BryanCutler/following{/other_user}","gists_url":"https://api.github.com/users/BryanCutler/gists{/gist_id}","starred_url":"https://api.github.com/users/BryanCutler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BryanCutler/subscriptions","organizations_url":"https://api.github.com/users/BryanCutler/orgs","repos_url":"https://api.github.com/users/BryanCutler/repos","events_url":"https://api.github.com/users/BryanCutler/events{/privacy}","received_events_url":"https://api.github.com/users/BryanCutler/received_events","type":"User","site_admin":false},"body":"The doctest uses default values for all params except `outputCol` and checks the transformed values, so this is really just testing that nothing fails if all param default values are used including `outputCol`","created_at":"2018-03-14T19:01:28Z","updated_at":"2018-03-14T19:01:28Z","html_url":"https://github.com/apache/spark/pull/16770#discussion_r174576552","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/16770","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/174576552"},"html":{"href":"https://github.com/apache/spark/pull/16770#discussion_r174576552"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/16770"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/16770","id":104208484,"html_url":"https://github.com/apache/spark/pull/16770","diff_url":"https://github.com/apache/spark/pull/16770.diff","patch_url":"https://github.com/apache/spark/pull/16770.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/16770","number":16770,"state":"open","locked":false,"title":"[SPARK-15009][PYTHON][ML] Construct a CountVectorizerModel from a vocabulary list","user":{"login":"BryanCutler","id":4534389,"avatar_url":"https://avatars3.githubusercontent.com/u/4534389?v=4","gravatar_id":"","url":"https://api.github.com/users/BryanCutler","html_url":"https://github.com/BryanCutler","followers_url":"https://api.github.com/users/BryanCutler/followers","following_url":"https://api.github.com/users/BryanCutler/following{/other_user}","gists_url":"https://api.github.com/users/BryanCutler/gists{/gist_id}","starred_url":"https://api.github.com/users/BryanCutler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BryanCutler/subscriptions","organizations_url":"https://api.github.com/users/BryanCutler/orgs","repos_url":"https://api.github.com/users/BryanCutler/repos","events_url":"https://api.github.com/users/BryanCutler/events{/privacy}","received_events_url":"https://api.github.com/users/BryanCutler/received_events","type":"User","site_admin":false},"body":"## What changes were proposed in this pull request?\r\n\r\nAdded a class method to construct CountVectorizerModel from a list of vocabulary strings, equivalent to the Scala version.  Introduced a common param base class `_CountVectorizerParams` to allow the Python model to also own the parameters.  This now matches the Scala class hierarchy. \r\n\r\n## How was this patch tested?\r\n\r\nAdded to CountVectorizer doctests to do a transform on a model constructed from vocab, and unit test to verify params and vocab are constructed correctly.","created_at":"2017-02-01T19:51:52Z","updated_at":"2018-03-14T19:01:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e94155b5a3f1bc308260032699712a262d463ab6","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/16770/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/16770/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/16770/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/5220ff131deb6914ee0b899d9c95a2861f057d55","head":{"label":"BryanCutler:pyspark-CountVectorizerModel-vocab_ctor-SPARK-15009","ref":"pyspark-CountVectorizerModel-vocab_ctor-SPARK-15009","sha":"5220ff131deb6914ee0b899d9c95a2861f057d55","user":{"login":"BryanCutler","id":4534389,"avatar_url":"https://avatars3.githubusercontent.com/u/4534389?v=4","gravatar_id":"","url":"https://api.github.com/users/BryanCutler","html_url":"https://github.com/BryanCutler","followers_url":"https://api.github.com/users/BryanCutler/followers","following_url":"https://api.github.com/users/BryanCutler/following{/other_user}","gists_url":"https://api.github.com/users/BryanCutler/gists{/gist_id}","starred_url":"https://api.github.com/users/BryanCutler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BryanCutler/subscriptions","organizations_url":"https://api.github.com/users/BryanCutler/orgs","repos_url":"https://api.github.com/users/BryanCutler/repos","events_url":"https://api.github.com/users/BryanCutler/events{/privacy}","received_events_url":"https://api.github.com/users/BryanCutler/received_events","type":"User","site_admin":false},"repo":{"id":34092463,"name":"spark","full_name":"BryanCutler/spark","owner":{"login":"BryanCutler","id":4534389,"avatar_url":"https://avatars3.githubusercontent.com/u/4534389?v=4","gravatar_id":"","url":"https://api.github.com/users/BryanCutler","html_url":"https://github.com/BryanCutler","followers_url":"https://api.github.com/users/BryanCutler/followers","following_url":"https://api.github.com/users/BryanCutler/following{/other_user}","gists_url":"https://api.github.com/users/BryanCutler/gists{/gist_id}","starred_url":"https://api.github.com/users/BryanCutler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BryanCutler/subscriptions","organizations_url":"https://api.github.com/users/BryanCutler/orgs","repos_url":"https://api.github.com/users/BryanCutler/repos","events_url":"https://api.github.com/users/BryanCutler/events{/privacy}","received_events_url":"https://api.github.com/users/BryanCutler/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/BryanCutler/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/BryanCutler/spark","forks_url":"https://api.github.com/repos/BryanCutler/spark/forks","keys_url":"https://api.github.com/repos/BryanCutler/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/BryanCutler/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/BryanCutler/spark/teams","hooks_url":"https://api.github.com/repos/BryanCutler/spark/hooks","issue_events_url":"https://api.github.com/repos/BryanCutler/spark/issues/events{/number}","events_url":"https://api.github.com/repos/BryanCutler/spark/events","assignees_url":"https://api.github.com/repos/BryanCutler/spark/assignees{/user}","branches_url":"https://api.github.com/repos/BryanCutler/spark/branches{/branch}","tags_url":"https://api.github.com/repos/BryanCutler/spark/tags","blobs_url":"https://api.github.com/repos/BryanCutler/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/BryanCutler/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/BryanCutler/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/BryanCutler/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/BryanCutler/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/BryanCutler/spark/languages","stargazers_url":"https://api.github.com/repos/BryanCutler/spark/stargazers","contributors_url":"https://api.github.com/repos/BryanCutler/spark/contributors","subscribers_url":"https://api.github.com/repos/BryanCutler/spark/subscribers","subscription_url":"https://api.github.com/repos/BryanCutler/spark/subscription","commits_url":"https://api.github.com/repos/BryanCutler/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/BryanCutler/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/BryanCutler/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/BryanCutler/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/BryanCutler/spark/contents/{+path}","compare_url":"https://api.github.com/repos/BryanCutler/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/BryanCutler/spark/merges","archive_url":"https://api.github.com/repos/BryanCutler/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/BryanCutler/spark/downloads","issues_url":"https://api.github.com/repos/BryanCutler/spark/issues{/number}","pulls_url":"https://api.github.com/repos/BryanCutler/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/BryanCutler/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/BryanCutler/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/BryanCutler/spark/labels{/name}","releases_url":"https://api.github.com/repos/BryanCutler/spark/releases{/id}","deployments_url":"https://api.github.com/repos/BryanCutler/spark/deployments","created_at":"2015-04-17T02:35:36Z","updated_at":"2016-01-22T20:22:43Z","pushed_at":"2018-03-14T18:58:09Z","git_url":"git://github.com/BryanCutler/spark.git","ssh_url":"git@github.com:BryanCutler/spark.git","clone_url":"https://github.com/BryanCutler/spark.git","svn_url":"https://github.com/BryanCutler/spark","homepage":null,"size":253261,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":2,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"f6b49f9d1b6f218408197f7272c1999fe3d94328","user":{"login":"apache","id":47359,"avatar_url":"https://avatars0.githubusercontent.com/u/47359?v=4","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":17165658,"name":"spark","full_name":"apache/spark","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars0.githubusercontent.com/u/47359?v=4","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/spark","description":"Mirror of Apache Spark","fork":false,"url":"https://api.github.com/repos/apache/spark","forks_url":"https://api.github.com/repos/apache/spark/forks","keys_url":"https://api.github.com/repos/apache/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/spark/teams","hooks_url":"https://api.github.com/repos/apache/spark/hooks","issue_events_url":"https://api.github.com/repos/apache/spark/issues/events{/number}","events_url":"https://api.github.com/repos/apache/spark/events","assignees_url":"https://api.github.com/repos/apache/spark/assignees{/user}","branches_url":"https://api.github.com/repos/apache/spark/branches{/branch}","tags_url":"https://api.github.com/repos/apache/spark/tags","blobs_url":"https://api.github.com/repos/apache/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/spark/languages","stargazers_url":"https://api.github.com/repos/apache/spark/stargazers","contributors_url":"https://api.github.com/repos/apache/spark/contributors","subscribers_url":"https://api.github.com/repos/apache/spark/subscribers","subscription_url":"https://api.github.com/repos/apache/spark/subscription","commits_url":"https://api.github.com/repos/apache/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/spark/contents/{+path}","compare_url":"https://api.github.com/repos/apache/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/spark/merges","archive_url":"https://api.github.com/repos/apache/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/spark/downloads","issues_url":"https://api.github.com/repos/apache/spark/issues{/number}","pulls_url":"https://api.github.com/repos/apache/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/spark/labels{/name}","releases_url":"https://api.github.com/repos/apache/spark/releases{/id}","deployments_url":"https://api.github.com/repos/apache/spark/deployments","created_at":"2014-02-25T08:00:08Z","updated_at":"2018-03-14T18:51:44Z","pushed_at":"2018-03-14T18:58:14Z","git_url":"git://github.com/apache/spark.git","ssh_url":"git@github.com:apache/spark.git","clone_url":"https://github.com/apache/spark.git","svn_url":"https://github.com/apache/spark","homepage":null,"size":269405,"stargazers_count":16478,"watchers_count":16478,"language":"Scala","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":15196,"mirror_url":null,"archived":false,"open_issues_count":476,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":15196,"open_issues":476,"watchers":16478,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/16770"},"html":{"href":"https://github.com/apache/spark/pull/16770"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/16770"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/16770/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/16770/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/16770/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/5220ff131deb6914ee0b899d9c95a2861f057d55"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"BryanCutler"}}