From 8cf8265d94fe383003e731df41821be957274f66 Mon Sep 17 00:00:00 2001 From: Athitya Kumar Date: Sat, 8 Apr 2017 01:32:10 +0530 Subject: [PATCH] Tries resolving rubocop 0.48.1 release offenses - try #1 --- .rubocop.yml | 4 ++++ lib/daru/accessors/gsl_wrapper.rb | 2 +- lib/daru/category.rb | 2 +- lib/daru/core/query.rb | 8 ++++---- lib/daru/dataframe.rb | 8 ++++---- lib/daru/date_time/index.rb | 2 +- lib/daru/index/index.rb | 6 +++--- lib/daru/io/io.rb | 2 +- lib/daru/maths/statistics/dataframe.rb | 10 +++++----- lib/daru/maths/statistics/vector.rb | 4 ++-- lib/daru/plotting/nyaplot/dataframe.rb | 4 ++-- lib/daru/vector.rb | 4 ++-- 12 files changed, 30 insertions(+), 26 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index ae9ead4b2..e43e47085 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,6 +2,10 @@ AllCops: Include: - 'lib/**/*' Exclude: + - 'daru.gemspec' + - 'Rakefile' + - 'Gemfile' + - 'Guardfile' - '**/*.erb' - 'spec/*' - 'spec/**/*' diff --git a/lib/daru/accessors/gsl_wrapper.rb b/lib/daru/accessors/gsl_wrapper.rb index ef5424cd6..6f4ae2f18 100644 --- a/lib/daru/accessors/gsl_wrapper.rb +++ b/lib/daru/accessors/gsl_wrapper.rb @@ -65,7 +65,7 @@ def compact ::GSL::Vector.alloc(@data.to_a - [Float::NAN]) end - [:mean, :min, :max, :prod, :sum].each do |method| + %i[mean min max prod sum].each do |method| define_method(method) do compact.send(method.to_sym) rescue nil end diff --git a/lib/daru/category.rb b/lib/daru/category.rb index 506fefd1b..5ffe00689 100644 --- a/lib/daru/category.rb +++ b/lib/daru/category.rb @@ -461,7 +461,7 @@ def coding_scheme= scheme @coding_scheme = scheme end - CODING_SCHEMES = [:dummy, :deviation, :helmert, :simple].freeze + CODING_SCHEMES = %i[dummy deviation helmert simple].freeze # Contrast code the vector acording to the coding scheme set. # @note To set the coding scheme use #coding_scheme= diff --git a/lib/daru/core/query.rb b/lib/daru/core/query.rb index 2151a5829..e83667730 100644 --- a/lib/daru/core/query.rb +++ b/lib/daru/core/query.rb @@ -9,13 +9,13 @@ def initialize barry end def & other - BoolArray.new @barry.zip(other.barry).map { |b, o| b && o } + BoolArray.new(@barry.zip(other.barry).map { |b, o| b && o }) end alias :and :& def | other - BoolArray.new @barry.zip(other.barry).map { |b, o| b || o } + BoolArray.new(@barry.zip(other.barry).map { |b, o| b || o }) end alias :or :| @@ -39,11 +39,11 @@ def inspect class << self def apply_scalar_operator operator, data, other - BoolArray.new data.map { |d| !!d.send(operator, other) if d.respond_to?(operator) } + BoolArray.new(data.map { |d| !!d.send(operator, other) if d.respond_to?(operator) }) end def apply_vector_operator operator, vector, other - BoolArray.new vector.zip(other).map { |d, o| !!d.send(operator, o) } + BoolArray.new(vector.zip(other).map { |d, o| !!d.send(operator, o) }) end def df_where data_frame, bool_array diff --git a/lib/daru/dataframe.rb b/lib/daru/dataframe.rb index 210eb8193..eb8583ef2 100644 --- a/lib/daru/dataframe.rb +++ b/lib/daru/dataframe.rb @@ -929,7 +929,7 @@ def keep_vector_if # creates a new vector with the data of a given field which the block returns true def filter_vector vec, &block - Daru::Vector.new each_row.select(&block).map { |row| row[vec] } + Daru::Vector.new(each_row.select(&block).map { |row| row[vec] }) end # Iterates over each row and retains it in a new DataFrame if the block returns @@ -1047,7 +1047,7 @@ def missing_values_rows missing_values=[nil] alias :vector_missing_values :missing_values_rows def has_missing_data? - !!@data.any? { |vec| vec.include_values?(*Daru::MISSING_VALUES) } + @data.any? { |vec| vec.include_values?(*Daru::MISSING_VALUES) } end alias :flawed? :has_missing_data? deprecate :has_missing_data?, :include_values?, 2016, 10 @@ -1393,7 +1393,7 @@ def vectors= new_index # df.rename_vectors :a => :alpha, :c => :gamma # df.vectors.to_a #=> [:alpha, :b, :gamma] def rename_vectors name_map - existing_targets = name_map.select { |k,v| k != v }.values & vectors.to_a + existing_targets = name_map.reject { |k,v| k == v }.values & vectors.to_a delete_vectors(*existing_targets) new_names = vectors.to_a.map { |v| name_map[v] ? name_map[v] : v } @@ -2066,7 +2066,7 @@ def dispatch_to_axis_pl(axis, method, *args, &block) end end - AXES = [:row, :vector].freeze + AXES = %i[row vector].freeze def extract_axis names, default=:vector if AXES.include?(names.last) diff --git a/lib/daru/date_time/index.rb b/lib/daru/date_time/index.rb index 8cf494d43..631027437 100644 --- a/lib/daru/date_time/index.rb +++ b/lib/daru/date_time/index.rb @@ -490,7 +490,7 @@ def self._load data # @return [Array] Array containing minutes of each index. # @!method sec # @return [Array] Array containing seconds of each index. - [:year, :month, :day, :hour, :min, :sec].each do |meth| + %i[year month day hour min sec].each do |meth| define_method(meth) do each_with_object([]) do |d, arr| arr << d.send(meth) diff --git a/lib/daru/index/index.rb b/lib/daru/index/index.rb index 38e2a35f7..a781277c2 100644 --- a/lib/daru/index/index.rb +++ b/lib/daru/index/index.rb @@ -120,7 +120,7 @@ def subset *indexes Daru::Index.new indexes else # Assume 'indexes' contain positions not indexes - Daru::Index.new indexes.map { |k| key k } + Daru::Index.new(indexes.map { |k| key k }) end end @@ -290,11 +290,11 @@ def by_range rng def by_multi_key *key if include? key[0] - Daru::Index.new key.map { |k| k } + Daru::Index.new(key.map { |k| k }) else # Assume the user is specifing values for index not keys # Return index object having keys corresponding to values provided - Daru::Index.new key.map { |k| key k } + Daru::Index.new(key.map { |k| key k }) end end diff --git a/lib/daru/io/io.rb b/lib/daru/io/io.rb index 1d443d4e7..17a0494f4 100644 --- a/lib/daru/io/io.rb +++ b/lib/daru/io/io.rb @@ -187,7 +187,7 @@ def load filename private - DARU_OPT_KEYS = [:clone, :order, :index, :name].freeze + DARU_OPT_KEYS = %i[clone order index name].freeze def from_csv_prepare_opts opts opts[:col_sep] ||= ',' diff --git a/lib/daru/maths/statistics/dataframe.rb b/lib/daru/maths/statistics/dataframe.rb index ed7594ac4..9420ac38b 100644 --- a/lib/daru/maths/statistics/dataframe.rb +++ b/lib/daru/maths/statistics/dataframe.rb @@ -22,7 +22,7 @@ module DataFrame # Calculate the minimum value of each numeric vector # @!method product # Compute the product of each numeric vector - [:mean, :variance_sample, :range, :median, :mode, :std, :sum, :count, :min, :product].each do |meth| + %i[mean variance_sample range median mode std sum count min product].each do |meth| define_method(meth) do compute_stats meth end @@ -70,9 +70,9 @@ def max opts={} # @!method rolling_variance # Calculate moving variance # @param [Integer] n (10) Loopback length. Default to 10. - [ - :cumsum,:standardize,:acf,:ema,:rolling_mean,:rolling_median,:rolling_max, - :rolling_min,:rolling_count,:rolling_std,:rolling_variance, :rolling_sum + %i[ + cumsum standardize acf ema rolling_mean rolling_median rolling_max + rolling_min rolling_count rolling_std rolling_variance rolling_sum ].each do |meth| define_method(meth) do |*args| apply_method_to_numerics meth, *args @@ -88,7 +88,7 @@ def max opts={} # be applied to numeric vectors. Default is [:count, :mean, :std, :max, # :min]. Methods will be applied in the specified order. def describe methods=nil - methods ||= [:count, :mean, :std, :min, :max] + methods ||= %i[count mean std min max] description_hash = {} numeric_vectors.each do |vec| diff --git a/lib/daru/maths/statistics/vector.rb b/lib/daru/maths/statistics/vector.rb index 4c0e7e1df..ea9a06630 100644 --- a/lib/daru/maths/statistics/vector.rb +++ b/lib/daru/maths/statistics/vector.rb @@ -41,7 +41,7 @@ def mode # be applied to vectors. Default is [:count, :mean, :std, :max, # :min]. Methods will be applied in the specified order. def describe methods=nil - methods ||= [:count, :mean, :std, :min, :max] + methods ||= %i[count mean std min max] description = methods.map { |m| send(m) } Daru::Vector.new(description, index: methods, name: :statistics) end @@ -571,7 +571,7 @@ def rolling function, n=10 # @!method rolling_variance # Calculate rolling variance # @param [Integer] n (10) Loopback length - [:count, :mean, :median, :max, :min, :sum, :std, :variance].each do |meth| + %i[count mean median max min sum std variance].each do |meth| define_method("rolling_#{meth}".to_sym) do |n=10| rolling(meth, n) end diff --git a/lib/daru/plotting/nyaplot/dataframe.rb b/lib/daru/plotting/nyaplot/dataframe.rb index 72475327b..b52d238f4 100644 --- a/lib/daru/plotting/nyaplot/dataframe.rb +++ b/lib/daru/plotting/nyaplot/dataframe.rb @@ -38,7 +38,7 @@ def plot_without_category opts diagram = case - when !([:scatter, :bar, :line, :histogram] & types).empty? + when !(%i[scatter bar line histogram] & types).empty? plot_regular_diagrams plot, opts when types.include?(:box) plot_box_diagram plot @@ -102,7 +102,7 @@ def apply_variant_to_diagrams diagrams, category_opts, type end end - SHAPES = %w(circle triangle-up diamond square triangle-down cross).freeze + SHAPES = %w[circle triangle-up diamond square triangle-down cross].freeze def get_shape type validate_type type, :scatter SHAPES.cycle diff --git a/lib/daru/vector.rb b/lib/daru/vector.rb index cc86b880a..554b11d83 100644 --- a/lib/daru/vector.rb +++ b/lib/daru/vector.rb @@ -555,7 +555,7 @@ def category? # Get index of element def index_of element case dtype - when :array then @index.key @data.index { |x| x.eql? element } + when :array then @index.key(@data.index { |x| x.eql? element }) else @index.key @data.index(element) end end @@ -669,7 +669,7 @@ def recode! dt=nil, &block def delete_if return to_enum(:delete_if) unless block_given? - keep_e, keep_i = each_with_index.select { |n, _i| !yield(n) }.transpose + keep_e, keep_i = each_with_index.reject { |n, _i| yield(n) }.transpose @data = cast_vector_to @dtype, keep_e @index = Daru::Index.new(keep_i)