{"action":"created","comment":{"url":"https://api.github.com/repos/v0dro/daru/pulls/comments/69390656","id":69390656,"diff_hunk":"@@ -0,0 +1,883 @@\n+module Daru\n+  module Category # rubocop:disable Metrics/ModuleLength\n+    attr_accessor :base_category\n+    attr_reader :index, :coding_scheme, :name\n+\n+    # For debuggin. To be removed\n+    attr_reader :array, :cat_hash, :map_int_cat\n+\n+    # Initializes a vector to store categorical data.\n+    # @param [Array] data the categorical data\n+    # @param [Hash] opts the options\n+    # @option opts [Boolean] :ordered true if data is ordered, false otherwise\n+    # @option opts [Array] :categories categories to associate with the vector.\n+    #   It add extra categories if specified and provides order of categories also.\n+    # @option opts [object] :index gives index to vector. By default its from 0 to size-1\n+    # @option opts [Hash] :metadata metadata associated with the vector.\n+    # @return the categorical data created\n+    # @example\n+    #   dv = Daru::Vector.new [:a, 1, :a, 1, :c],\n+    #     type: :category,\n+    #     ordered: true,\n+    #     categories: [:a, :b, :c, 1]\n+    #   # => #<Daru::Vector(5)>\n+    #   #   0   a\n+    #   #   1   1\n+    #   #   2   a\n+    #   #   3   1\n+    #   #   4   c\n+    def initialize_category data, opts={}\n+      @type = :category\n+      initialize_core_attributes data\n+\n+      if opts[:categories]\n+        validate_categories(opts[:categories])\n+        add_extra_categories(opts[:categories] - categories)\n+        order_with opts[:categories]\n+      end\n+\n+      # Specify if the categories are ordered or not.\n+      # By default its unordered\n+      @ordered = opts[:ordered] || false\n+\n+      # The coding scheme to code with. Default is dummy coding.\n+      @coding_scheme = :dummy\n+\n+      # Base category which won't be present in the coding\n+      @base_category = @cat_hash.keys.first\n+\n+      # Stores the name of the vector\n+      @name = opts[:name]\n+\n+      # Index of the vector\n+      @index = coerce_index opts[:index]\n+\n+      # Store metadata\n+      @metadata = opts[:metadata] || {}\n+      self\n+    end\n+\n+    def name= new_name\n+      @name = new_name\n+      self\n+    end\n+\n+    def plotting_library= lib\n+      case lib\n+      when :gruff, :nyaplot\n+        @plotting_library = lib\n+        extend Module.const_get(\n+          \"Daru::Plotting::Category::#{lib.to_s.capitalize}Library\"\n+        ) if Daru.send(\"has_#{lib}?\".to_sym)\n+      else\n+        raise ArguementError, \"Plotting library #{lib} not supported. \"\\\n+          'Supported libraries are :nyaplot and :gruff'\n+      end\n+    end\n+\n+    alias_method :rename, :name=\n+\n+    # Returns an enumerator that enumerates on categorical data\n+    # @return [Enumerator] an enumerator that enumerates over data stored in vector\n+    def each\n+      return enum_for(:each) unless block_given?\n+      @array.each { |pos| yield cat_from_int pos }\n+      self\n+    end\n+\n+    # Returns all categorical data\n+    # @return [Array] array of all categorical data which vector is storing\n+    # @example\n+    #   dv = Daru::Vector.new [:a, 1, :a, 1, :c], type: :category\n+    #   dv.to_a\n+    #   # => [:a, 1, :a, 1, :c]\n+    def to_a\n+      each.to_a\n+    end\n+\n+    # Duplicated a vector\n+    # @return [Daru::Vector] duplicated vector\n+    # @example\n+    #   dv = Daru::Vector.new [:a, 1, :a, 1, :c], type: :category\n+    #   dv.dup\n+    #   # => #<Daru::Vector(5)>\n+    #   #   0   a\n+    #   #   1   1\n+    #   #   2   a\n+    #   #   3   1\n+    #   #   4   c\n+    def dup\n+      Daru::Vector.new to_a.dup,\n+        name: @name,\n+        metadata: @metadata.dup,\n+        index: @index.dup,\n+        type: :category,\n+        categories: categories,\n+        ordered: ordered?\n+    end\n+\n+    # Associates a category to the vector.\n+    # @param [Array] *new_categories new categories to be associated\n+    # @example\n+    #   dv = Daru::Vector.new [:a, 1, :a, 1, :c], type: :category\n+    #   dv.add_category :b\n+    #   dv.categories\n+    #   # => [:a, :b, :c, 1]\n+    def add_category(*new_categories)\n+      new_categories -= categories\n+      add_extra_categories new_categories\n+    end\n+\n+    # Returns frequency of given category\n+    # @param [object] category given category whose count has to be founded\n+    # @return count/frequency of given category\n+    # @example\n+    #   dv = Daru::Vector.new [:a, 1, :a, 1, :c], type: :category\n+    #   dv.count :a\n+    #   # => 2\n+    def count category\n+      raise ArgumentError, \"Invalid category #{category}\" unless\n+        categories.include?(category)\n+\n+      @cat_hash[category].size\n+    end\n+\n+    # Returns a vector storing count/frequency of each category\n+    # @return [Daru::Vector] Return a vector whose indexes are categories\n+    #   and corresponding values are its count\n+    # @example\n+    #   dv = Daru::Vector.new [:a, 1, :a, 1, :c], type: :category\n+    #   dv.frequencies\n+    #   # => #<Daru::Vector(4)>\n+    #   #   a   2\n+    #   #   b   0\n+    #   #   c   1\n+    #   #   1   2\n+    def frequencies type=:count\n+      counts = @cat_hash.values.map(&:size)\n+      values =\n+        case type\n+        when :count\n+          counts\n+        when :fraction\n+          counts.map { |c| c / size.to_f }\n+        when :percentage\n+          counts.map { |c| c / size.to_f * 100 }\n+        end\n+      Daru::Vector.new values, index: categories, name: name\n+    end\n+\n+    # Returns vector for indexes/positions specified\n+    # @param [Array] *indexes indexes/positions for which values has to be retrived\n+    # @note Since it accepts both indexes and postions. In case of collision,\n+    #   arguement will be treated as index\n+    # @return vector containing values specified at specified indexes/positions\n+    # @example\n+    #   dv = Daru::Vector.new [:a, 1, :a, 1, :c],\n+    #     type: :category,\n+    #     index: 'a'..'e'\n+    #   dv[:a, 1]\n+    #   # => #<Daru::Vector(2)>\n+    #   #   a   a\n+    #   #   b   1\n+    #   dv[0, 1]\n+    #   # => #<Daru::Vector(2)>\n+    #   #   a   a\n+    #   #   b   1\n+    def [] *indexes\n+      positions = @index.pos(*indexes)\n+      return category_from_position(positions) if positions.is_a? Integer\n+\n+      Daru::Vector.new positions.map { |pos| category_from_position pos },\n+        index: @index.subset(*indexes),\n+        name: @name,\n+        type: :category,\n+        ordered: @ordered,\n+        metadata: @metadata,\n+        categories: categories\n+    end\n+\n+    # Returns vector for positions specified.\n+    # @param [Array] *positions positions at which values to be retrived.\n+    # @return vector containing values specified at specified positions\n+    # @example\n+    #   dv = Daru::Vector.new [:a, 1, :a, 1, :c], type: :category\n+    #   dv.at 0..-2\n+    #   # => #<Daru::Vector(4)>\n+    #   #   0   a\n+    #   #   1   1\n+    #   #   2   a\n+    #   #   3   1\n+    def at *positions\n+      original_positions = positions\n+      positions = coerce_positions(*positions)\n+      validate_positions(*positions)\n+\n+      return category_from_position(positions) if positions.is_a? Integer\n+\n+      Daru::Vector.new positions.map { |pos| category_from_position(pos) },\n+        index: @index.at(*original_positions),\n+        name: @name,\n+        type: :category,\n+        ordered: @ordered,\n+        metadata: @metadata,\n+        categories: categories\n+    end\n+\n+    # Modifies values at specified indexes/positions.\n+    # @note In order to add a new category you need to associate it via #add_category\n+    # @param [Array] *indexes indexes/positions at which to modify value\n+    # @param [object] val value to assign at specific indexes/positions\n+    # @return modified vector\n+    # @example\n+    #   dv = Daru::Vector.new [:a, 1, :a, 1, :c], type: :category\n+    #   dv.add_category :b\n+    #   dv[0] = :b\n+    #   dv\n+    #   # => #<Daru::Vector(5)>\n+    #   #   0   b\n+    #   #   1   1\n+    #   #   2   a\n+    #   #   3   1\n+    #   #   4   c\n+    def []= *indexes, val\n+      positions = @index.pos(*indexes)\n+\n+      if positions.is_a? Numeric\n+        modify_category_at positions, val\n+      else\n+        positions.each { |pos| modify_category_at pos, val }\n+      end\n+      self\n+    end\n+\n+    # Modifies values at specified positions.\n+    # @param [Array] positions positions at which to modify value\n+    # @param [object] val value to assign at specific positions\n+    # @return modified vector\n+    # @example\n+    #   dv = Daru::Vector.new [:a, 1, :a, 1, :c], type: :category\n+    #   dv.add_category :b\n+    #   dv.set_at [0, 1], :b\n+    #   # => #<Daru::Vector(5)>\n+    #   #   0   b\n+    #   #   1   b\n+    #   #   2   a\n+    #   #   3   1\n+    #   #   4   c\n+    def set_at positions, val\n+      validate_positions(*positions)\n+      positions.map { |pos| modify_category_at pos, val }\n+      self\n+    end\n+\n+    # Size of categorical data.\n+    # @return total number of values in the vector\n+    # @example\n+    #   dv = Daru::Vector.new [:a, 1, :a, 1, :c], type: :category\n+    #   dv.size\n+    #   # => 5\n+    def size\n+      @array.size\n+    end\n+\n+    # Tells whether vector is ordered or not.\n+    # @return [Boolean] true if vector is ordered, false otherwise\n+    # @example\n+    #   dv = Daru::Vector.new [:a, 1, :a, 1, :c], type: :category\n+    #   dv.ordered?\n+    #   # => false\n+    def ordered?\n+      @ordered\n+    end\n+\n+    # Make categorical data ordered or unordered.\n+    # @param [Boolean] bool true if categorical data is to be to ordered, false otherwise\n+    # @example\n+    #   dv = Daru::Vector.new [:a, 1, :a, 1, :c], type: :category\n+    #   dv.ordered = true\n+    #   dv.ordered?\n+    #   # => true\n+    def ordered= bool\n+      @ordered = bool\n+    end\n+\n+    # Returns all the categories with the inherent order\n+    # @return [Array] categories of the vector with the order\n+    # @example\n+    #   dv = Daru::Vector.new [:a, 1, :a, 1, :c],\n+    #     type: :category,\n+    #     categories: [:a, :b, :c, 1]\n+    #   dv.categories\n+    #   # => [:a, :b, :c, 1]\n+    def categories\n+      @cat_hash.keys\n+    end\n+\n+    alias_method :order, :categories\n+\n+    # Sets order of the categories.\n+    # @note If extra categories are specified, they get added too.\n+    # @param [Array] cat_with_order categories specifying their order\n+    # @example\n+    #   dv = Daru::Vector.new [:a, 1, :a, 1, :c], type: :category\n+    #   dv.categories = [:a, :b, :c, 1]\n+    #   dv.categories\n+    #   # => [:a, :b, :c, 1]\n+    def categories= cat_with_order\n+      validate_categories(cat_with_order)\n+      add_extra_categories(cat_with_order - categories)\n+      order_with cat_with_order\n+    end\n+\n+    # Rename categories.\n+    # @param [Hash] old_to_new a hash mapping categories whose name to be changed\n+    #   to their new names\n+    # @example\n+    #   dv = Daru::Vector.new [:a, 1, :a, 1, :c], type: :category\n+    #   dv.rename_categories :a => :b\n+    #   dv\n+    #   # => #<Daru::Vector(5)>\n+    #   #   0   b\n+    #   #   1   1\n+    #   #   2   b\n+    #   #   3   1\n+    #   #   4   c\n+    def rename_categories old_to_new\n+      old_categories = categories\n+      data = to_a.map do |cat|\n+        old_to_new.include?(cat) ? old_to_new[cat] : cat\n+      end\n+\n+      initialize_core_attributes data\n+      self.categories = (old_categories - old_to_new.keys) | old_to_new.values\n+      self\n+    end\n+\n+    def remove_unused_categories\n+      old_categories = categories\n+\n+      initialize_core_attributes to_a\n+      self.categories = old_categories & categories\n+      self\n+    end\n+\n+    # Returns the minimum category acording to the order specified.\n+    # @note This operation will only work if vector is ordered.\n+    #   To set the vector ordered do `vector.ordered = true`\n+    # @return [object] the minimum category acording to the order\n+    # @example\n+    #   dv = Daru::Vector.new ['second', 'second', 'third', 'first'],\n+    #     categories: ['first', 'second', 'third']\n+    #   dv.min\n+    #   # => 'first'\n+    def min\n+      assert_ordered :min\n+      categories.first\n+    end\n+\n+    # Returns the maximum category acording to the order specified.\n+    # @note This operation will only work if vector is ordered.\n+    #   To set the vector ordered do `vector.ordered = true`\n+    # @return [object] the maximum category acording to the order\n+    # @example\n+    #   dv = Daru::Vector.new ['second', 'second', 'third', 'first'],\n+    #     categories: ['first', 'second', 'third']\n+    #   dv.max\n+    #   # => 'third'\n+    def max\n+      assert_ordered :max\n+      categories.last\n+    end\n+\n+    # Sorts the vector in the order specified.\n+    # @note This operation will only work if vector is ordered.\n+    #   To set the vector ordered, do `vector.ordered = true`\n+    # @return [Daru::Vector] sorted vector\n+    # @example\n+    #   dv = Daru::Vector.new ['second', 'second', 'third', 'first'],\n+    #     categories: ['first', 'second', 'thrid'],\n+    #     type: :categories,\n+    #     ordered: true\n+    #   dv.sort!\n+    #   # => #<Daru::Vector(4)>\n+    #   #       3  first\n+    #   #       0 second\n+    #   #       1 second\n+    #   #       2  third\n+    def sort! # rubocop:disable Metrics/AbcSize\n+      # TODO: Simply the code\n+      assert_ordered :sort\n+\n+      # Build sorted index\n+      old_index = @index.to_a\n+      new_index = @cat_hash.values.map do |positions|\n+        old_index.values_at(*positions)\n+      end.flatten\n+      @index = @index.class.new new_index\n+\n+      # Build sorted data\n+      @cat_hash = categories.inject([{}, 0]) do |acc, cat|\n+        hash, count = acc\n+        cat_count = @cat_hash[cat].size\n+        cat_count.times { |i| @array[count+i] = int_from_cat(cat) }\n+        hash[cat] = (count...(cat_count+count)).to_a\n+        [hash, count + cat_count]\n+      end.first\n+\n+      self\n+    end\n+\n+    def sort\n+      dup.sort!\n+    end\n+\n+    # Set coding scheme\n+    # @param [Symbol] scheme to set\n+    # @example\n+    #   dv = Daru::Vector.new [:a, 1, :a, 1, :c], type: :category\n+    #   dv.coding_scheme = :deviation\n+    #   dv.coding_scheme\n+    #   # => :deviation\n+    def coding_scheme= scheme\n+      raise ArgumentError, \"Unknown or unsupported coding scheme #{scheme}.\" unless\n+        CODING_SCHEMES.include? scheme\n+      @coding_scheme = scheme\n+    end\n+\n+    CODING_SCHEMES = [:dummy, :deviation, :helmert, :simple].freeze\n+\n+    # Contrast code the vector acording to the coding scheme set.\n+    # @note To set the coding scheme use #coding_scheme=\n+    # @param [true, false] full true if you want k variables for k categories,\n+    #   false if you want k-1 variables for k categories\n+    # @return [Daru::DataFrame] dataframe containing all coded variables\n+    # @example\n+    #   dv = Daru::Vector.new [:a, 1, :a, 1, :c], type: :category\n+    #   dv.contrast_code\n+    #   # => #<Daru::DataFrame(5x2)>\n+    #   #         daru_1 daru_c\n+    #   #       0      0      0\n+    #   #       1      1      0\n+    #   #       2      0      0\n+    #   #       3      1      0\n+    #   #       4      0      1\n+    def contrast_code opts={}\n+      if opts[:user_defined]\n+        user_defined_coding(opts[:user_defined])\n+      else\n+        # TODO: Make various coding schemes code DRY\n+        send(\"#{coding_scheme}_coding\".to_sym, opts[:full] || false)\n+      end\n+    end\n+\n+    # Two categorical vectors are equal if their index and corresponding values are same\n+    # return [true, false] true if two vectors are similar\n+    # @example\n+    #   dv = Daru::Vector.new [:a, 1, :a, 1, :c], type: :category\n+    #   other = Daru::Vector.new [:a, 1, :a, 1, :c],\n+    #     type: :category,\n+    #     index: 1..5\n+    #   dv == other\n+    #   # => false\n+    def == other\n+      size == other.size &&\n+        to_a == other.to_a &&\n+        index == other.index\n+    end\n+\n+    # Returns integer coding for categorical data in the order starting from 0.\n+    # For example if order is [:a, :b, :c], then :a, will be coded as 0, :b as 1 and :c as 2\n+    # @return [Array] integer coding of all values of vector\n+    # @example\n+    #   dv = Daru::Vector.new [:a, 1, :a, 1, :c],\n+    #     type: :category,\n+    #     categories: [:a, :b, :c, 1]\n+    #   dv.to_ints\n+    #   # => [0, 1, 0, 1, 2]\n+    def to_ints\n+      @array\n+    end\n+\n+    # Over rides original inspect for pretty printing in irb\n+    def inspect spacing=20, threshold=15\n+      row_headers = index.is_a?(MultiIndex) ? index.sparse_tuples : index.to_a\n+\n+      \"#<#{self.class}(#{size})#{metadata && !metadata.empty? ? metadata.inspect : ''}>\\n\" +\n+        Formatters::Table.format(\n+          to_a.lazy.map { |v| [v] },\n+          headers: @name && [@name],\n+          row_headers: row_headers,\n+          threshold: threshold,\n+          spacing: spacing\n+        )\n+    end\n+\n+    # Convert to html for iruby\n+    def to_html threshold=30\n+      path =\n+        if index.is_a?(MultiIndex)\n+          File.expand_path('../iruby/templates/vector_mi.html.erb', __FILE__)\n+        else\n+          File.expand_path('../iruby/templates/vector.html.erb', __FILE__)\n+        end\n+      ERB.new(File.read(path).strip).result(binding)\n+    end\n+\n+    def to_s\n+      to_html\n+    end\n+\n+    # Reorder the vector with given positions\n+    # @note Unlike #reindex! which takes index as input, it takes\n+    #   positions as an input to reorder the vector\n+    # @param [Array] order the order to reorder the vector with\n+    # @return reordered vector\n+    # @example\n+    #   dv = Daru::Vector.new [3, 2, 1], index: ['c', 'b', 'a'], type: :category\n+    #   dv.reorder! [2, 1, 0]\n+    #   # => #<Daru::Vector(3)>\n+    #   #   a   1\n+    #   #   b   2\n+    #   #   c   3\n+    def reorder! order\n+      raise ArgumentError, 'Invalid order specified' unless\n+        order.sort == size.times.to_a\n+      # TODO: Room for optimization\n+      old_data = to_a\n+      new_data = order.map { |i| old_data[i] }\n+      initialize_core_attributes new_data\n+      self\n+    end\n+\n+    # Sets new index for vector. Preserves index->value correspondence.\n+    # @note Unlike #reorder! which takes positions as input it takes\n+    #   index as an input to reorder the vector\n+    # @param [Daru::Index, Daru::MultiIndex, Array] idx new index to order with\n+    # @return [Daru::Vector] vector reindexed with new index\n+    # @example\n+    #   dv = Daru::Vector.new [3, 2, 1], index: ['c', 'b', 'a'], type: :category\n+    #   dv.reindex! ['a', 'b', 'c']\n+    #   # => #<Daru::Vector(3)>\n+    #   #   a   1\n+    #   #   b   2\n+    #   #   c   3\n+    def reindex! idx\n+      idx = Daru::Index.new idx unless idx.is_a? Daru::Index\n+      raise ArgumentError, 'Invalid index specified' unless\n+        idx.to_a.sort == index.to_a.sort\n+\n+      old_categories = categories\n+      data = idx.map { |i| self[i] }\n+      initialize_core_attributes data\n+      self.categories = old_categories\n+      self.index = idx\n+      self\n+    end\n+\n+    # Non-destructive version of #reorder!\n+    # See #reorder!\n+    def reorder order\n+      dup.reorder! order\n+    end\n+\n+    # Non-destructive version of #reindex!\n+    # See #reindex!\n+    def reindex index\n+      dup.reindex! index\n+    end\n+\n+    {\n+      eq: :==,\n+      not_eq: :!=,\n+      lt: :<,\n+      lteq: :<=,\n+      mt: :>,\n+      mteq: :>=\n+    }.each do |method, operator|\n+      define_method(method) do |other|\n+        mod = Daru::Core::Query\n+        if other.is_a?(Daru::Vector)\n+          mod.apply_vector_operator operator, to_ints, other.to_ints\n+        else\n+          mod.apply_scalar_operator operator, @array, int_from_cat(other)\n+        end\n+      end\n+    end\n+    alias :gt :mt\n+    alias :gteq :mteq\n+\n+    # For querying the data\n+    # @param [object] arel like query syntax\n+    # @return [Daru::Vector] Vector which makes the conditions true\n+    # @example\n+    #   dv = Daru::Vector.new ['I', 'II', 'I', 'III', 'I', 'II'],\n+    #     type: :category,\n+    #     ordered: true,\n+    #     categories: ['I', 'II', 'III']\n+    #   dv.where(dv.mt('I') & dv.lt('III'))\n+    #   # => #<Daru::Vector(2)>\n+    #   #   1  II\n+    #   #   5  II\n+    def where bool_array\n+      Daru::Core::Query.vector_where self, bool_array\n+    end\n+\n+    # Gives the summary of data using following parameters\n+    # - size: size of the data\n+    # - categories: total number of categories\n+    # - max_freq: Max no of times a category occurs\n+    # - max_category: The category which occurs max no of times\n+    # - min_freq: Min no of times a category occurs\n+    # - min_category: The category which occurs min no of times\n+    # @return [Daru::Vector] Vector with index as following parameters\n+    #   and values as values to these parameters\n+    # @example\n+    #   dv = Daru::Vector.new [:a, 1, :a, 1, :c], type: :category\n+    #   dv.summary\n+    #   # => #<Daru::Vector(6)>\n+    #   #         size            5\n+    #   #   categories            3\n+    #   #     max_freq            2\n+    #   # max_category            a\n+    #   #     min_freq            1\n+    #   # min_category            c\n+    def summary\n+      values = {\n+        size: size,\n+        categories: categories.size,\n+        max_freq: @cat_hash.values.map(&:size).max,\n+        max_category: @cat_hash.keys.max_by { |cat| @cat_hash[cat].size },\n+        min_freq: @cat_hash.values.map(&:size).min,\n+        min_category: @cat_hash.keys.min_by { |cat| @cat_hash[cat].size }\n+      }\n+\n+      Daru::Vector.new values\n+    end\n+\n+    alias_method :describe, :summary\n+\n+    # Raises TypeError since the vector to be converted is already of\n+    #   type category\n+    # @return [TypeError] Raises an exception\n+    def to_category\n+      raise TypeError, 'The vector is already of type category.'","path":"lib/daru/category.rb","position":664,"original_position":664,"commit_id":"defeef508c364a39c275fcab1ee6b299f2854c27","original_commit_id":"defeef508c364a39c275fcab1ee6b299f2854c27","user":{"login":"zverok","id":129656,"avatar_url":"https://avatars.githubusercontent.com/u/129656?v=3","gravatar_id":"","url":"https://api.github.com/users/zverok","html_url":"https://github.com/zverok","followers_url":"https://api.github.com/users/zverok/followers","following_url":"https://api.github.com/users/zverok/following{/other_user}","gists_url":"https://api.github.com/users/zverok/gists{/gist_id}","starred_url":"https://api.github.com/users/zverok/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zverok/subscriptions","organizations_url":"https://api.github.com/users/zverok/orgs","repos_url":"https://api.github.com/users/zverok/repos","events_url":"https://api.github.com/users/zverok/events{/privacy}","received_events_url":"https://api.github.com/users/zverok/received_events","type":"User","site_admin":false},"body":"Typically, in such cases `return self` is more appropriate solution:\r\n```ruby\r\n[1,2,3].to_a\r\n# => [1, 2, 3] \r\n{a: 1, b: 2}.to_h\r\n# => {:a=>1, :b=>2} \r\n```\r\n\r\nI mean, when we are raising an exception in this case, what kind of error we want to signalize about?..","created_at":"2016-07-03T12:13:45Z","updated_at":"2016-07-03T12:13:45Z","html_url":"https://github.com/v0dro/daru/pull/134#discussion_r69390656","pull_request_url":"https://api.github.com/repos/v0dro/daru/pulls/134","_links":{"self":{"href":"https://api.github.com/repos/v0dro/daru/pulls/comments/69390656"},"html":{"href":"https://github.com/v0dro/daru/pull/134#discussion_r69390656"},"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 and Categorical Data","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-07-03T12:13:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"897a0b5ce6b7de519ada324ef9ed23e1adac4dcf","assignee":null,"assignees":[],"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/defeef508c364a39c275fcab1ee6b299f2854c27","head":{"label":"lokeshh:cat_index","ref":"cat_index","sha":"defeef508c364a39c275fcab1ee6b299f2854c27","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-07-02T12:49:11Z","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":3672,"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":"dc53f4ee976185291b730119b00e3a56d52b3b25","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-29T22:46:19Z","pushed_at":"2016-07-02T18:06:00Z","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":3926,"stargazers_count":129,"watchers_count":129,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":35,"mirror_url":null,"open_issues_count":42,"forks":35,"open_issues":42,"watchers":129,"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/defeef508c364a39c275fcab1ee6b299f2854c27"}}}}
{"actor":{"display_login":"zverok"}}