{"action":"created","comment":{"url":"https://api.github.com/repos/v0dro/daru/pulls/comments/65822009","id":65822009,"diff_hunk":"@@ -392,4 +480,138 @@ def sparse_tuples\n       }\n     end\n   end\n+\n+  class CategoricalIndex < Index\n+    # Create a categorical index object.\n+    # @param indexes [Array<object>] array of indexes\n+    # @return [object] categorical index\n+    # @example\n+    #   Daru::CategoricalIndex.new [:a, 1, :a, 1, :c]\n+    #   # => #<Daru::CategoricalIndex(5): {a, 1, a, 1, c}>\n+    def initialize indexes\n+      # Create a hash to map each category to positional indexes\n+      categories = indexes.each_with_index.group_by(&:first)\n+      @cat_hash = categories.map { |cat, group| [cat, group.map(&:last)] }.to_h\n+\n+      # Map each category to a unique integer for effective storage in @array\n+      map_cat_int = categories.keys.each_with_index.to_h\n+\n+      # Inverse mapping of map_cat_int\n+      @map_int_cat = map_cat_int.invert\n+\n+      # To link every instance to its category,\n+      # it stores integer for every instance representing its category\n+      @array = map_cat_int.values_at(*indexes)\n+    end\n+\n+    # @return [object] duplicate index object\n+    def dup\n+      # Improve it by intializing index by hash\n+      Daru::CategoricalIndex.new to_a\n+    end\n+\n+    # @param index [object] the index value to look for\n+    # @return [true, false] true if index is included, false otherwise\n+    def include? index\n+      @cat_hash.include? index\n+    end\n+\n+    # Returns array of categories\n+    # @example\n+    #   x = Daru::CategoricalIndex.new [:a, 1, :a, 1, :c]\n+    #   x.categories\n+    #   # => [:a, 1, :c]\n+    def categories\n+      @cat_hash.keys\n+    end\n+\n+    # Returns positions given categories or positions\n+    # @note If the argument does not a valid category it treats it as position\n+    #   value and return it as it is.\n+    # @param [Array<object>] *indexes categories or positions\n+    # @example\n+    #   x = Daru::CategoricalIndex.new [:a, 1, :a, 1, :c]\n+    #   x.pos :a, 1\n+    #   # => [0, 1, 2, 3]\n+    def pos *indexes\n+      positions = indexes.map do |index|\n+        if include? index\n+          @cat_hash[index]\n+        elsif index.is_a?(Numeric) && index < @array.size\n+          index\n+        else\n+          raise IndexError, \"#{index.inspect} is neither a valid category\"\\\n+            ' nor a valid position'\n+        end\n+      end\n+\n+      positions.flatten!\n+      positions.size == 1 ? positions.first : positions.sort\n+    end\n+\n+    # Returns index value from position\n+    # @param pos [Integer] the position to look for\n+    # @return [object] category corresponding to position\n+    def index_from_pos pos\n+      @map_int_cat[@array[pos]]","path":"lib/daru/index.rb","position":215,"original_position":215,"commit_id":"1bbae75399fcd1942b09c21585ba728d9bd72eb7","original_commit_id":"a815d889e11b123fc19e25024da7870e7b616a40","user":{"login":"lokeshh","id":7677524,"avatar_url":"https://avatars.githubusercontent.com/u/7677524?v=3","gravatar_id":"","url":"https://api.github.com/users/lokeshh","html_url":"https://github.com/lokeshh","followers_url":"https://api.github.com/users/lokeshh/followers","following_url":"https://api.github.com/users/lokeshh/following{/other_user}","gists_url":"https://api.github.com/users/lokeshh/gists{/gist_id}","starred_url":"https://api.github.com/users/lokeshh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lokeshh/subscriptions","organizations_url":"https://api.github.com/users/lokeshh/orgs","repos_url":"https://api.github.com/users/lokeshh/repos","events_url":"https://api.github.com/users/lokeshh/events{/privacy}","received_events_url":"https://api.github.com/users/lokeshh/received_events","type":"User","site_admin":false},"body":"I am not good with naming. What should I name it?","created_at":"2016-06-05T18:34:46Z","updated_at":"2016-06-05T18:34:46Z","html_url":"https://github.com/v0dro/daru/pull/134#discussion_r65822009","pull_request_url":"https://api.github.com/repos/v0dro/daru/pulls/134","_links":{"self":{"href":"https://api.github.com/repos/v0dro/daru/pulls/comments/65822009"},"html":{"href":"https://github.com/v0dro/daru/pull/134#discussion_r65822009"},"pull_request":{"href":"https://api.github.com/repos/v0dro/daru/pulls/134"}}},"pull_request":{"url":"https://api.github.com/repos/v0dro/daru/pulls/134","id":71005450,"html_url":"https://github.com/v0dro/daru/pull/134","diff_url":"https://github.com/v0dro/daru/pull/134.diff","patch_url":"https://github.com/v0dro/daru/pull/134.patch","issue_url":"https://api.github.com/repos/v0dro/daru/issues/134","number":134,"state":"open","locked":false,"title":"[WIP] Categorical Index","user":{"login":"lokeshh","id":7677524,"avatar_url":"https://avatars.githubusercontent.com/u/7677524?v=3","gravatar_id":"","url":"https://api.github.com/users/lokeshh","html_url":"https://github.com/lokeshh","followers_url":"https://api.github.com/users/lokeshh/followers","following_url":"https://api.github.com/users/lokeshh/following{/other_user}","gists_url":"https://api.github.com/users/lokeshh/gists{/gist_id}","starred_url":"https://api.github.com/users/lokeshh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lokeshh/subscriptions","organizations_url":"https://api.github.com/users/lokeshh/orgs","repos_url":"https://api.github.com/users/lokeshh/repos","events_url":"https://api.github.com/users/lokeshh/events{/privacy}","received_events_url":"https://api.github.com/users/lokeshh/received_events","type":"User","site_admin":false},"body":"The coding begins!\r\n\r\nThis PR adds `CategoricalIndex` to Daru. ","created_at":"2016-05-23T05:08:33Z","updated_at":"2016-06-05T18:34:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7f55f6c79b46a41c30fe1654d20d8e8226e71ade","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/v0dro/daru/pulls/134/commits","review_comments_url":"https://api.github.com/repos/v0dro/daru/pulls/134/comments","review_comment_url":"https://api.github.com/repos/v0dro/daru/pulls/comments{/number}","comments_url":"https://api.github.com/repos/v0dro/daru/issues/134/comments","statuses_url":"https://api.github.com/repos/v0dro/daru/statuses/1bbae75399fcd1942b09c21585ba728d9bd72eb7","head":{"label":"lokeshh:cat_index","ref":"cat_index","sha":"1bbae75399fcd1942b09c21585ba728d9bd72eb7","user":{"login":"lokeshh","id":7677524,"avatar_url":"https://avatars.githubusercontent.com/u/7677524?v=3","gravatar_id":"","url":"https://api.github.com/users/lokeshh","html_url":"https://github.com/lokeshh","followers_url":"https://api.github.com/users/lokeshh/followers","following_url":"https://api.github.com/users/lokeshh/following{/other_user}","gists_url":"https://api.github.com/users/lokeshh/gists{/gist_id}","starred_url":"https://api.github.com/users/lokeshh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lokeshh/subscriptions","organizations_url":"https://api.github.com/users/lokeshh/orgs","repos_url":"https://api.github.com/users/lokeshh/repos","events_url":"https://api.github.com/users/lokeshh/events{/privacy}","received_events_url":"https://api.github.com/users/lokeshh/received_events","type":"User","site_admin":false},"repo":{"id":51312435,"name":"daru","full_name":"lokeshh/daru","owner":{"login":"lokeshh","id":7677524,"avatar_url":"https://avatars.githubusercontent.com/u/7677524?v=3","gravatar_id":"","url":"https://api.github.com/users/lokeshh","html_url":"https://github.com/lokeshh","followers_url":"https://api.github.com/users/lokeshh/followers","following_url":"https://api.github.com/users/lokeshh/following{/other_user}","gists_url":"https://api.github.com/users/lokeshh/gists{/gist_id}","starred_url":"https://api.github.com/users/lokeshh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lokeshh/subscriptions","organizations_url":"https://api.github.com/users/lokeshh/orgs","repos_url":"https://api.github.com/users/lokeshh/repos","events_url":"https://api.github.com/users/lokeshh/events{/privacy}","received_events_url":"https://api.github.com/users/lokeshh/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/lokeshh/daru","description":"Data Analysis in RUby","fork":true,"url":"https://api.github.com/repos/lokeshh/daru","forks_url":"https://api.github.com/repos/lokeshh/daru/forks","keys_url":"https://api.github.com/repos/lokeshh/daru/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lokeshh/daru/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lokeshh/daru/teams","hooks_url":"https://api.github.com/repos/lokeshh/daru/hooks","issue_events_url":"https://api.github.com/repos/lokeshh/daru/issues/events{/number}","events_url":"https://api.github.com/repos/lokeshh/daru/events","assignees_url":"https://api.github.com/repos/lokeshh/daru/assignees{/user}","branches_url":"https://api.github.com/repos/lokeshh/daru/branches{/branch}","tags_url":"https://api.github.com/repos/lokeshh/daru/tags","blobs_url":"https://api.github.com/repos/lokeshh/daru/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lokeshh/daru/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lokeshh/daru/git/refs{/sha}","trees_url":"https://api.github.com/repos/lokeshh/daru/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lokeshh/daru/statuses/{sha}","languages_url":"https://api.github.com/repos/lokeshh/daru/languages","stargazers_url":"https://api.github.com/repos/lokeshh/daru/stargazers","contributors_url":"https://api.github.com/repos/lokeshh/daru/contributors","subscribers_url":"https://api.github.com/repos/lokeshh/daru/subscribers","subscription_url":"https://api.github.com/repos/lokeshh/daru/subscription","commits_url":"https://api.github.com/repos/lokeshh/daru/commits{/sha}","git_commits_url":"https://api.github.com/repos/lokeshh/daru/git/commits{/sha}","comments_url":"https://api.github.com/repos/lokeshh/daru/comments{/number}","issue_comment_url":"https://api.github.com/repos/lokeshh/daru/issues/comments{/number}","contents_url":"https://api.github.com/repos/lokeshh/daru/contents/{+path}","compare_url":"https://api.github.com/repos/lokeshh/daru/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lokeshh/daru/merges","archive_url":"https://api.github.com/repos/lokeshh/daru/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lokeshh/daru/downloads","issues_url":"https://api.github.com/repos/lokeshh/daru/issues{/number}","pulls_url":"https://api.github.com/repos/lokeshh/daru/pulls{/number}","milestones_url":"https://api.github.com/repos/lokeshh/daru/milestones{/number}","notifications_url":"https://api.github.com/repos/lokeshh/daru/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lokeshh/daru/labels{/name}","releases_url":"https://api.github.com/repos/lokeshh/daru/releases{/id}","deployments_url":"https://api.github.com/repos/lokeshh/daru/deployments","created_at":"2016-02-08T17:09:21Z","updated_at":"2016-05-28T07:11:32Z","pushed_at":"2016-06-05T18:31:34Z","git_url":"git://github.com/lokeshh/daru.git","ssh_url":"git@github.com:lokeshh/daru.git","clone_url":"https://github.com/lokeshh/daru.git","svn_url":"https://github.com/lokeshh/daru","homepage":null,"size":3728,"stargazers_count":1,"watchers_count":1,"language":"Ruby","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":1,"default_branch":"master"}},"base":{"label":"v0dro:master","ref":"master","sha":"9f31896a561c822593e2918213274859ddc0f10c","user":{"login":"v0dro","id":2629909,"avatar_url":"https://avatars.githubusercontent.com/u/2629909?v=3","gravatar_id":"","url":"https://api.github.com/users/v0dro","html_url":"https://github.com/v0dro","followers_url":"https://api.github.com/users/v0dro/followers","following_url":"https://api.github.com/users/v0dro/following{/other_user}","gists_url":"https://api.github.com/users/v0dro/gists{/gist_id}","starred_url":"https://api.github.com/users/v0dro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/v0dro/subscriptions","organizations_url":"https://api.github.com/users/v0dro/orgs","repos_url":"https://api.github.com/users/v0dro/repos","events_url":"https://api.github.com/users/v0dro/events{/privacy}","received_events_url":"https://api.github.com/users/v0dro/received_events","type":"User","site_admin":false},"repo":{"id":24784998,"name":"daru","full_name":"v0dro/daru","owner":{"login":"v0dro","id":2629909,"avatar_url":"https://avatars.githubusercontent.com/u/2629909?v=3","gravatar_id":"","url":"https://api.github.com/users/v0dro","html_url":"https://github.com/v0dro","followers_url":"https://api.github.com/users/v0dro/followers","following_url":"https://api.github.com/users/v0dro/following{/other_user}","gists_url":"https://api.github.com/users/v0dro/gists{/gist_id}","starred_url":"https://api.github.com/users/v0dro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/v0dro/subscriptions","organizations_url":"https://api.github.com/users/v0dro/orgs","repos_url":"https://api.github.com/users/v0dro/repos","events_url":"https://api.github.com/users/v0dro/events{/privacy}","received_events_url":"https://api.github.com/users/v0dro/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/v0dro/daru","description":"Data Analysis in RUby","fork":false,"url":"https://api.github.com/repos/v0dro/daru","forks_url":"https://api.github.com/repos/v0dro/daru/forks","keys_url":"https://api.github.com/repos/v0dro/daru/keys{/key_id}","collaborators_url":"https://api.github.com/repos/v0dro/daru/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/v0dro/daru/teams","hooks_url":"https://api.github.com/repos/v0dro/daru/hooks","issue_events_url":"https://api.github.com/repos/v0dro/daru/issues/events{/number}","events_url":"https://api.github.com/repos/v0dro/daru/events","assignees_url":"https://api.github.com/repos/v0dro/daru/assignees{/user}","branches_url":"https://api.github.com/repos/v0dro/daru/branches{/branch}","tags_url":"https://api.github.com/repos/v0dro/daru/tags","blobs_url":"https://api.github.com/repos/v0dro/daru/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/v0dro/daru/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/v0dro/daru/git/refs{/sha}","trees_url":"https://api.github.com/repos/v0dro/daru/git/trees{/sha}","statuses_url":"https://api.github.com/repos/v0dro/daru/statuses/{sha}","languages_url":"https://api.github.com/repos/v0dro/daru/languages","stargazers_url":"https://api.github.com/repos/v0dro/daru/stargazers","contributors_url":"https://api.github.com/repos/v0dro/daru/contributors","subscribers_url":"https://api.github.com/repos/v0dro/daru/subscribers","subscription_url":"https://api.github.com/repos/v0dro/daru/subscription","commits_url":"https://api.github.com/repos/v0dro/daru/commits{/sha}","git_commits_url":"https://api.github.com/repos/v0dro/daru/git/commits{/sha}","comments_url":"https://api.github.com/repos/v0dro/daru/comments{/number}","issue_comment_url":"https://api.github.com/repos/v0dro/daru/issues/comments{/number}","contents_url":"https://api.github.com/repos/v0dro/daru/contents/{+path}","compare_url":"https://api.github.com/repos/v0dro/daru/compare/{base}...{head}","merges_url":"https://api.github.com/repos/v0dro/daru/merges","archive_url":"https://api.github.com/repos/v0dro/daru/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/v0dro/daru/downloads","issues_url":"https://api.github.com/repos/v0dro/daru/issues{/number}","pulls_url":"https://api.github.com/repos/v0dro/daru/pulls{/number}","milestones_url":"https://api.github.com/repos/v0dro/daru/milestones{/number}","notifications_url":"https://api.github.com/repos/v0dro/daru/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/v0dro/daru/labels{/name}","releases_url":"https://api.github.com/repos/v0dro/daru/releases{/id}","deployments_url":"https://api.github.com/repos/v0dro/daru/deployments","created_at":"2014-10-04T08:23:21Z","updated_at":"2016-06-01T21:20:29Z","pushed_at":"2016-06-05T18:31:35Z","git_url":"git://github.com/v0dro/daru.git","ssh_url":"git@github.com:v0dro/daru.git","clone_url":"https://github.com/v0dro/daru.git","svn_url":"https://github.com/v0dro/daru","homepage":null,"size":3619,"stargazers_count":113,"watchers_count":113,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":32,"mirror_url":null,"open_issues_count":35,"forks":32,"open_issues":35,"watchers":113,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/v0dro/daru/pulls/134"},"html":{"href":"https://github.com/v0dro/daru/pull/134"},"issue":{"href":"https://api.github.com/repos/v0dro/daru/issues/134"},"comments":{"href":"https://api.github.com/repos/v0dro/daru/issues/134/comments"},"review_comments":{"href":"https://api.github.com/repos/v0dro/daru/pulls/134/comments"},"review_comment":{"href":"https://api.github.com/repos/v0dro/daru/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/v0dro/daru/pulls/134/commits"},"statuses":{"href":"https://api.github.com/repos/v0dro/daru/statuses/1bbae75399fcd1942b09c21585ba728d9bd72eb7"}}}}
{"actor":{"display_login":"lokeshh"}}