Sha256: 0ec88fa1e5d64510c22bb08279f72e8328d7d7fcf811dfb944ff1ab47821b26e

Contents?: true

Size: 648 Bytes

Versions: 13

Compression:

Stored size: 648 Bytes

Contents

module Eps
  module Utils
    def self.column_type(c, k)
      if !c
        raise ArgumentError, "Missing column: #{k}"
      elsif c.all? { |v| v.nil? }
        # goes here for empty as well
        nil
      elsif c.any? { |v| v.nil? }
        raise ArgumentError, "Missing values in column #{k}"
      elsif c.all? { |v| v.is_a?(Numeric) }
        "numeric"
      elsif c.all? { |v| v.is_a?(String) }
        "categorical"
      elsif c.all? { |v| v == true || v == false }
        "categorical" # boolean
      else
        raise ArgumentError, "Column values must be all numeric, all string, or all boolean: #{k}"
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
eps-0.5.0 lib/eps/utils.rb
eps-0.4.1 lib/eps/utils.rb
eps-0.4.0 lib/eps/utils.rb
eps-0.3.9 lib/eps/utils.rb
eps-0.3.8 lib/eps/utils.rb
eps-0.3.7 lib/eps/utils.rb
eps-0.3.6 lib/eps/utils.rb
eps-0.3.5 lib/eps/utils.rb
eps-0.3.4 lib/eps/utils.rb
eps-0.3.3 lib/eps/utils.rb
eps-0.3.2 lib/eps/utils.rb
eps-0.3.1 lib/eps/utils.rb
eps-0.3.0 lib/eps/utils.rb