daru 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +20 -7
  3. data/CONTRIBUTING.md +1 -1
  4. data/History.md +48 -1
  5. data/README.md +3 -3
  6. data/benchmarks/statistics.rb +6 -6
  7. data/benchmarks/where_clause.rb +1 -1
  8. data/benchmarks/where_vs_filter.rb +1 -1
  9. data/daru.gemspec +3 -2
  10. data/lib/daru.rb +14 -6
  11. data/lib/daru/accessors/gsl_wrapper.rb +1 -1
  12. data/lib/daru/accessors/nmatrix_wrapper.rb +2 -0
  13. data/lib/daru/category.rb +1 -1
  14. data/lib/daru/core/group_by.rb +32 -15
  15. data/lib/daru/core/query.rb +4 -4
  16. data/lib/daru/dataframe.rb +196 -48
  17. data/lib/daru/date_time/index.rb +7 -5
  18. data/lib/daru/formatters/table.rb +1 -0
  19. data/lib/daru/index/index.rb +121 -33
  20. data/lib/daru/index/multi_index.rb +83 -3
  21. data/lib/daru/io/csv/converters.rb +18 -0
  22. data/lib/daru/io/io.rb +80 -11
  23. data/lib/daru/io/sql_data_source.rb +10 -0
  24. data/lib/daru/iruby/templates/dataframe.html.erb +3 -50
  25. data/lib/daru/iruby/templates/dataframe_mi.html.erb +3 -56
  26. data/lib/daru/iruby/templates/dataframe_mi_tbody.html.erb +35 -0
  27. data/lib/daru/iruby/templates/dataframe_mi_thead.html.erb +21 -0
  28. data/lib/daru/iruby/templates/dataframe_tbody.html.erb +28 -0
  29. data/lib/daru/iruby/templates/dataframe_thead.html.erb +21 -0
  30. data/lib/daru/iruby/templates/vector.html.erb +3 -25
  31. data/lib/daru/iruby/templates/vector_mi.html.erb +3 -34
  32. data/lib/daru/iruby/templates/vector_mi_tbody.html.erb +26 -0
  33. data/lib/daru/iruby/templates/vector_mi_thead.html.erb +8 -0
  34. data/lib/daru/iruby/templates/vector_tbody.html.erb +17 -0
  35. data/lib/daru/iruby/templates/vector_thead.html.erb +8 -0
  36. data/lib/daru/maths/statistics/dataframe.rb +9 -11
  37. data/lib/daru/maths/statistics/vector.rb +139 -32
  38. data/lib/daru/plotting/gruff/dataframe.rb +13 -15
  39. data/lib/daru/plotting/nyaplot/category.rb +1 -1
  40. data/lib/daru/plotting/nyaplot/dataframe.rb +4 -4
  41. data/lib/daru/plotting/nyaplot/vector.rb +1 -2
  42. data/lib/daru/vector.rb +169 -80
  43. data/lib/daru/version.rb +1 -1
  44. data/spec/category_spec.rb +19 -19
  45. data/spec/core/group_by_spec.rb +47 -0
  46. data/spec/core/query_spec.rb +55 -50
  47. data/spec/daru_spec.rb +22 -0
  48. data/spec/dataframe_spec.rb +118 -6
  49. data/spec/date_time/index_spec.rb +34 -16
  50. data/spec/extensions/rserve_spec.rb +1 -1
  51. data/spec/fixtures/boolean_converter_test.csv +5 -0
  52. data/spec/fixtures/eciresults.html +394 -0
  53. data/spec/fixtures/empty_rows_test.csv +17 -0
  54. data/spec/fixtures/macau.html +3691 -0
  55. data/spec/fixtures/macd_data.csv +150 -0
  56. data/spec/fixtures/moneycontrol.html +6812 -0
  57. data/spec/fixtures/url_test.txt~ +0 -0
  58. data/spec/fixtures/valid_markup.html +62 -0
  59. data/spec/fixtures/wiki_climate.html +1243 -0
  60. data/spec/fixtures/wiki_table_info.html +631 -0
  61. data/spec/formatters/table_formatter_spec.rb +29 -0
  62. data/spec/index/categorical_index_spec.rb +33 -33
  63. data/spec/index/index_spec.rb +134 -41
  64. data/spec/index/multi_index_spec.rb +115 -31
  65. data/spec/io/io_spec.rb +201 -0
  66. data/spec/io/sql_data_source_spec.rb +31 -41
  67. data/spec/iruby/dataframe_spec.rb +17 -19
  68. data/spec/iruby/vector_spec.rb +26 -28
  69. data/spec/maths/statistics/vector_spec.rb +136 -14
  70. data/spec/plotting/gruff/category_spec.rb +3 -3
  71. data/spec/plotting/gruff/dataframe_spec.rb +14 -4
  72. data/spec/plotting/gruff/vector_spec.rb +9 -9
  73. data/spec/plotting/nyaplot/category_spec.rb +5 -9
  74. data/spec/plotting/nyaplot/dataframe_spec.rb +72 -47
  75. data/spec/plotting/nyaplot/vector_spec.rb +5 -11
  76. data/spec/shared/vector_display_spec.rb +12 -14
  77. data/spec/spec_helper.rb +21 -0
  78. data/spec/support/matchers.rb +5 -0
  79. data/spec/vector_spec.rb +222 -72
  80. metadata +68 -23
  81. data/spec/fixtures/stock_data.csv +0 -500
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b584977ade16d5cfbd3bdd9da7202bbc2adae894
4
- data.tar.gz: 3de8ef80fc55c91c0f504543fda1f23b40b4db6b
3
+ metadata.gz: 10338f8d554cc2c70b2dcc2d8fd029e73446f4de
4
+ data.tar.gz: b848b5923eebe90577ef93d4c9e988d7aa09fe9b
5
5
  SHA512:
6
- metadata.gz: 3f498f5caa4dbc14c2ca884c45492e474442d3f067ecf673a0235f01ec1781bb96c6f6e764006dcbf349a68ea011ccd977d69fdeb324a202ffa4fc5351a3a7b9
7
- data.tar.gz: d209e60b566e0e900d9c62fca6a1fb9023cd09cd81194e9b331c59682f557d8917ca347978bd4ed9b614c8d1ba441126211f3dc15a691752733f5dca0200be5d
6
+ metadata.gz: ad6c0de4217a65a2c6245c4b969e98d970da47a08ce8128b060cd06a13ae415df6d5e7fdc7bba4c84115fc8559e80bea0a39c87efb1c3401df358f4df5d43117
7
+ data.tar.gz: 34abe4afd0c88c24d3d0bbd6f11df5efe554f50b0d3d045a8a969f4eae2232d8d1cfeead814e336da507ca94b3126447631699258fe1a5dc5ea736de77c587f8
@@ -2,6 +2,10 @@ AllCops:
2
2
  Include:
3
3
  - 'lib/**/*'
4
4
  Exclude:
5
+ - 'daru.gemspec'
6
+ - 'Rakefile'
7
+ - 'Gemfile'
8
+ - 'Guardfile'
5
9
  - '**/*.erb'
6
10
  - 'spec/*'
7
11
  - 'spec/**/*'
@@ -12,7 +16,7 @@ AllCops:
12
16
  TargetRubyVersion: 2.0
13
17
 
14
18
  # Preferred codebase style ---------------------------------------------
15
- Style/ExtraSpacing:
19
+ Layout/ExtraSpacing:
16
20
  AllowForAlignment: true
17
21
 
18
22
  Style/FormatString:
@@ -21,16 +25,16 @@ Style/FormatString:
21
25
  Style/AndOr:
22
26
  EnforcedStyle: conditionals
23
27
 
24
- Style/SpaceAroundEqualsInParameterDefault:
28
+ Layout/SpaceAroundEqualsInParameterDefault:
25
29
  EnforcedStyle: no_space
26
30
 
27
- Style/SpaceInsideBlockBraces:
31
+ Layout/SpaceInsideBlockBraces:
28
32
  EnforcedStyle: space
29
33
 
30
- Style/SpaceInsideHashLiteralBraces:
34
+ Layout/SpaceInsideHashLiteralBraces:
31
35
  EnforcedStyle: no_space
32
36
 
33
- Style/AlignParameters:
37
+ Layout/AlignParameters:
34
38
  EnforcedStyle: with_fixed_indentation
35
39
 
36
40
  Style/EmptyElse:
@@ -57,10 +61,10 @@ Style/SingleLineBlockParams:
57
61
  Style/PerlBackrefs:
58
62
  Enabled: false
59
63
 
60
- Style/SpaceAfterComma:
64
+ Layout/SpaceAfterComma:
61
65
  Enabled: false
62
66
 
63
- Style/SpaceAroundOperators:
67
+ Layout/SpaceAroundOperators:
64
68
  Enabled: false
65
69
 
66
70
  Style/EmptyCaseCondition:
@@ -69,6 +73,15 @@ Style/EmptyCaseCondition:
69
73
  Style/MultilineBlockChain:
70
74
  Enabled: false
71
75
 
76
+ # See https://github.com/bbatsov/rubocop/issues/4429
77
+ Style/YodaCondition:
78
+ Enabled: false
79
+
80
+ Style/PercentLiteralDelimiters:
81
+ PreferredDelimiters:
82
+ '%i': '[]'
83
+ '%w': '[]'
84
+
72
85
  # Neither of prefered styles are good enough :(
73
86
  Style/BlockDelimiters:
74
87
  Enabled: false
@@ -31,7 +31,7 @@ While preparing your pull requests, don't forget to check your code with Rubocop
31
31
  ## Basic Development Flow
32
32
 
33
33
  1. Create a new branch with `git checkout -b <branch_name>`.
34
- 2. Make your changes.
34
+ 2. Make your changes. Write tests covering every case how your feature will be used. If creating new files for tests, refer to the 'Testing' section [below](#Testing).
35
35
  3. Try out these changes with `rake pry`.
36
36
  4. Run the test suite with `rake spec`. (Alternatively you can use `guard` as described [here](https://github.com/SciRuby/daru/blob/master/CONTRIBUTING.md#testing). Also run Rubocop coding style guidelines with `rake cop`.
37
37
  5. Commit the changes with `git commit -am "briefly describe what you did"` and submit pull request.
data/History.md CHANGED
@@ -1,3 +1,50 @@
1
+ # 0.1.6 (04 August 2017)
2
+ * Major Enhancements
3
+ - Add support for reading HTML tables into DataFrames (@athityakumar)
4
+ - Add support for importing remote CSVs (@athityakumar, @anshuman23)
5
+ - Allow named indexes (@Shekharrajak)
6
+ - DataFrame GroupBy returns MultiIndex DataFrame (@Shekharrajak)
7
+ - Add new functions to Vector: max, min, index_of_max, index_of_min, max_by, min_by, index_of_max_by, index_of_min_by (@athityakumar)
8
+ - Add summary to DataFrame and Vector without reportbuilder (@ananyo2012)
9
+ - Add support for missing data for where clause (@athityakumar)
10
+
11
+ * Minor Enhancements
12
+ - Allow inserting or updating DataFrame vectors with single values (@baarkerlounger)
13
+ - Add a boolean converter to the CSV importer (@baarkerlounger)
14
+ - Fix documentation of replace_values method (@kojix2)
15
+ - Improve HTML table code of DataFrame and Vector (@Shekharrajak )
16
+ - Support CSV files with empty rows (@baarkerlounger)
17
+ - Better DataFrame and Vector to_s methods (@baarkerlounger)
18
+ - Add support for histogram to Vector moving average convergence-divergence (@parthm)
19
+ - Add support for negative arguments to Vector.lag (@parthm)
20
+ - Return Nyaplot instance instead of nil for Nyaplot Vector, Category and DataFrame (@Shekharrajak)
21
+ - Add global configurable error stream which allows error stream to be silenced (@sivagollapalli)
22
+ - Rubocop update and cleanup (@zverok)
23
+ - Improve performance of DataFrame covariance (@genya0407)
24
+ - Index [] to only take index value as argument (@ananyo2012)
25
+ - Better error raised when Vector is missing from DataFrame (@sivagollapalli)
26
+ - Add default order for DataFrame (@athityakumar)
27
+ - Add is_values to Index (@Shekharrajak)
28
+ - Improve spec style in IO/SQL data source spec (@dshvimer)
29
+ - Open SQLite databases by bath (@dshvimer)
30
+ - Remove unnecessary whitespace (@Shekharrajak)
31
+ - Remove the .svg from Travis CI build link (@athityakumar)
32
+ - Fix Travis CI icon in README (@athityakumar)
33
+ - Replace is_nil?, not_nil? with is_values (@lokeshh)
34
+ - Update contributing documentation (@v0dro)
35
+
36
+ * Fixes
37
+ - Fix missing axis labels for categorized scatter plot with Gruff (@xprazak2)
38
+ - Fix NMatrix Vector initialization when Vector has nils and no nm_type is given (@baarkerlounger)
39
+ - Fix head/tail methods on DataFrames with DateTime indexes and on Vector_at splat calls (@baarkerlounger)
40
+ - Fix empty DateTime Index (@zverok)
41
+ - Fix where clause when data contains missing/undefined values (@Shekharrajak)
42
+ - Fix apply_scalar_operator spec (@athityakumar)
43
+ - Change nil check to respond_to operator check for apply_scalar_operator (@athityakumar)
44
+ - Make where compatible with is_values (@athityakumar)
45
+ - Fix vector is_values method (@athityakumar)
46
+
47
+
1
48
  # 0.1.5 (30 January 2017)
2
49
  * Major Enhancements
3
50
  - Add Daru::Vector#group_by (@lokeshh).
@@ -19,7 +66,7 @@
19
66
  - `DataFrame#access_row` with integer index. (Yusuke Sangenya)
20
67
  - Add method alias for comparison operator. (Yusuke Sangenya)
21
68
  - Update Nokogiri version. (Yusuke Sangenya)
22
- - Return `Daru::Vector` for multiple modal values for `Daru::Vector#mode`. (baarkerlounger)
69
+ - Return `Daru::Vector` for multiple modal values for `Daru::Vector#mode`. (@baarkerlounger)
23
70
 
24
71
  * Fixes
25
72
  - Fix many to one joins. The prior version was shifting values in the left dataframe before checking whether values in the right dataframe should be shifted. They both need to be checked at the same time before shifting either. (@gnilrets)
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # daru - Data Analysis in RUby
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/daru.svg)](http://badge.fury.io/rb/daru)
4
- [![Build Status](https://travis-ci.org/v0dro/daru.svg)](https://travis-ci.org/v0dro/daru)
4
+ [![Build Status](https://travis-ci.org/SciRuby/daru.svg?branch=master)](https://travis-ci.org/SciRuby/daru)
5
5
  [![Gitter](https://badges.gitter.im/v0dro/daru.svg)](https://gitter.im/v0dro/daru?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
6
6
 
7
7
  ## Introduction
@@ -168,7 +168,7 @@ data_frame.where(
168
168
  ```
169
169
  ![con1](images/con1.png)
170
170
 
171
- *Plotting*
171
+ *Plotting*
172
172
 
173
173
  Daru supports plotting of interactive graphs with [nyaplot](https://github.com/domitry/nyaplot). You can easily create a plot with the `#plot` method. Here we plot the gallons sold on the Y axis and name of the brand on the X axis in a bar graph.
174
174
  ``` ruby
@@ -196,7 +196,7 @@ For details see [CONTRIBUTING](https://github.com/v0dro/daru/blob/master/CONTRIB
196
196
 
197
197
  ## Acknowledgements
198
198
 
199
- * Google and the Ruby Science Foundation for the Google Summer of Code 2016 grant for speed enhancements and implementation of support for categorical data. Special thanks to [@lokeshh](https://github.com/lokeshh), [@zverok](https://github.com/zverok) and [@agisga](https://github.com/agisga) for their efforts.
199
+ * Google and the Ruby Science Foundation for the Google Summer of Code 2016 grant for speed enhancements and implementation of support for categorical data. Special thanks to [@lokeshh](https://github.com/lokeshh), [@zverok](https://github.com/zverok) and [@agisga](https://github.com/agisga) for their efforts.
200
200
  * Google and the Ruby Science Foundation for the Google Summer of Code 2015 grant for further developing daru and integrating it with other ruby gems.
201
201
  * Thank you [last.fm](http://www.last.fm/) for making user data accessible to the public.
202
202
 
@@ -5,26 +5,26 @@ vector = Daru::Vector.new(
5
5
  (10**6).times.map.to_a.shuffle,
6
6
  missing_values: 100.times.map.to_a.shuffle
7
7
  )
8
-
8
+
9
9
  vector_gsl = Daru::Vector.new(
10
10
  10000.times.map.to_a.shuffle,
11
11
  missing_values: 100.times.map.to_a.shuffle,
12
12
  dtype: :gsl
13
- )
14
-
13
+ )
14
+
15
15
  Benchmark.bm do |x|
16
16
  x.report("Mean of a vector") do
17
17
  vector.mean
18
18
  end
19
-
19
+
20
20
  x.report("Minimum of a vector") do
21
21
  vector.min
22
22
  end
23
-
23
+
24
24
  x.report("Mean of a vector with data type gsl") do
25
25
  vector_gsl.mean
26
26
  end
27
-
27
+
28
28
  x.report "Minimum of a vector with data type gsl" do
29
29
  vector_gsl.min
30
30
  end
@@ -35,7 +35,7 @@ Benchmark.bm do |x|
35
35
  end
36
36
 
37
37
  # ====== Benchmarks ======
38
- #
38
+ #
39
39
  # Benchmarking DataFrame#where
40
40
  #
41
41
  # user system total real
@@ -22,7 +22,7 @@ Benchmark.bm do |x|
22
22
  end
23
23
 
24
24
  # ===== Benchmarks =====
25
- #
25
+ #
26
26
  # user system total real
27
27
  # where 0.000000 0.000000 0.000000 ( 0.002575)
28
28
  # filter_rows 0.210000 0.000000 0.210000 ( 0.205403)
@@ -52,7 +52,6 @@ EOF
52
52
 
53
53
  spec.add_runtime_dependency 'backports'
54
54
 
55
- spec.add_development_dependency 'reportbuilder', '~> 1.4'
56
55
  spec.add_development_dependency 'spreadsheet', '~> 1.1.1'
57
56
  spec.add_development_dependency 'bundler', '~> 1.10'
58
57
  spec.add_development_dependency 'rake', '~>10.5'
@@ -69,11 +68,13 @@ EOF
69
68
  spec.add_development_dependency 'dbd-sqlite3'
70
69
  spec.add_development_dependency 'dbi'
71
70
  spec.add_development_dependency 'activerecord', '~> 4.0'
71
+ spec.add_development_dependency 'mechanize'
72
72
  spec.add_development_dependency 'sqlite3'
73
- spec.add_development_dependency 'rubocop', '>= 0.40.0'
73
+ spec.add_development_dependency 'rubocop', '~> 0.49.0'
74
74
  spec.add_development_dependency 'ruby-prof'
75
75
  spec.add_development_dependency 'simplecov'
76
76
  spec.add_development_dependency 'gruff'
77
+ spec.add_development_dependency 'webmock'
77
78
  if RUBY_VERSION < '2.1.0'
78
79
  spec.add_development_dependency 'nokogiri', '<= 1.6.8.1'
79
80
  else
@@ -38,11 +38,13 @@ module Daru
38
38
 
39
39
  @plotting_library = :nyaplot
40
40
 
41
+ @error_stream = $stderr
42
+
41
43
  class << self
42
44
  # A variable which will set whether Vector metadata is updated immediately or lazily.
43
45
  # Call the #update method every time a values are set or removed in order to update
44
46
  # metadata like positions of missing values.
45
- attr_accessor :lazy_update
47
+ attr_accessor :lazy_update, :error_stream
46
48
  attr_reader :plotting_library
47
49
 
48
50
  def create_has_library(library)
@@ -72,6 +74,10 @@ module Daru
72
74
  raise ArgumentError, "Unsupported library #{lib}"
73
75
  end
74
76
  end
77
+
78
+ def error msg
79
+ error_stream.puts msg if error_stream
80
+ end
75
81
  end
76
82
 
77
83
  create_has_library :gsl
@@ -80,13 +86,13 @@ module Daru
80
86
  create_has_library :gruff
81
87
  end
82
88
 
83
- [['reportbuilder', '~>1.4'], ['spreadsheet', '~>1.1.1']].each do |lib|
89
+ {'spreadsheet' => '~>1.1.1', 'mechanize' => '~>2.7.5'}.each do |name, version|
84
90
  begin
85
- gem lib[0], lib[1]
86
- require lib[0]
91
+ gem name, version
92
+ require name
87
93
  rescue LoadError
88
- STDERR.puts "\nInstall the #{lib[0]} gem version #{lib[1]} for using"\
89
- " #{lib[0]} functions."
94
+ Daru.error "\nInstall the #{name} gem version #{version} for using"\
95
+ " #{name} functions."
90
96
  end
91
97
  end
92
98
 
@@ -98,6 +104,8 @@ require 'date'
98
104
 
99
105
  require 'daru/version.rb'
100
106
 
107
+ require 'open-uri'
108
+
101
109
  require 'daru/index/index.rb'
102
110
  require 'daru/index/multi_index.rb'
103
111
  require 'daru/index/categorical_index.rb'
@@ -65,7 +65,7 @@ if Daru.has_gsl?
65
65
  ::GSL::Vector.alloc(@data.to_a - [Float::NAN])
66
66
  end
67
67
 
68
- [:mean, :min, :max, :prod, :sum].each do |method|
68
+ %i[mean min max prod sum].each do |method|
69
69
  define_method(method) do
70
70
  compact.send(method.to_sym) rescue nil
71
71
  end
@@ -25,6 +25,8 @@ if Daru.has_nmatrix?
25
25
  attr_reader :size, :data, :nm_dtype
26
26
 
27
27
  def initialize vector, context, nm_dtype=:int32
28
+ # To avoid arrays with nils throwing TypeError for nil nm_dtype
29
+ nm_dtype = :object if nm_dtype.nil? && vector.any?(&:nil?)
28
30
  @size = vector.size
29
31
  @data = NMatrix.new [@size*2], vector.to_a, dtype: nm_dtype
30
32
  @context = context
@@ -461,7 +461,7 @@ module Daru
461
461
  @coding_scheme = scheme
462
462
  end
463
463
 
464
- CODING_SCHEMES = [:dummy, :deviation, :helmert, :simple].freeze
464
+ CODING_SCHEMES = %i[dummy deviation helmert simple].freeze
465
465
 
466
466
  # Contrast code the vector acording to the coding scheme set.
467
467
  # @note To set the coding scheme use #coding_scheme=
@@ -1,7 +1,7 @@
1
1
  module Daru
2
2
  module Core
3
3
  class GroupBy
4
- attr_reader :groups
4
+ attr_reader :groups, :df
5
5
 
6
6
  # Iterate over each group created by group_by. A DataFrame is yielded in
7
7
  # block.
@@ -32,12 +32,7 @@ module Daru
32
32
  # # => {4=>["test"], 2=>["me"], 6=>["please"]}
33
33
  #
34
34
  # - zverok, 2016-09-12
35
- keys = tuples.uniq.sort(&TUPLE_SORTER)
36
-
37
- keys.each do |key|
38
- @groups[key] = all_indices_for(tuples, key)
39
- end
40
- @groups.freeze
35
+ init_groups_df tuples, names
41
36
  end
42
37
 
43
38
  # Get a Daru::Vector of the size of each group.
@@ -201,15 +196,8 @@ module Daru
201
196
  transpose = elements.transpose
202
197
  rows = indexes.each.map { |idx| transpose[idx] }
203
198
 
204
- new_index =
205
- begin
206
- @context.index[indexes]
207
- rescue IndexError
208
- indexes
209
- end
210
-
211
199
  Daru::DataFrame.rows(
212
- rows, index: new_index, order: @context.vectors
200
+ rows, index: indexes, order: @context.vectors
213
201
  )
214
202
  end
215
203
 
@@ -251,8 +239,26 @@ module Daru
251
239
  Daru::Vector.new(result_hash.values, index: index)
252
240
  end
253
241
 
242
+ def inspect
243
+ @df.inspect
244
+ end
245
+
254
246
  private
255
247
 
248
+ def init_groups_df tuples, names
249
+ multi_index_tuples = []
250
+ keys = tuples.uniq.sort(&TUPLE_SORTER)
251
+ keys.each do |key|
252
+ indices = all_indices_for(tuples, key)
253
+ @groups[key] = indices
254
+ indices.each do |indice|
255
+ multi_index_tuples << key + [indice]
256
+ end
257
+ end
258
+ @groups.freeze
259
+ @df = resultant_context(multi_index_tuples, names) unless multi_index_tuples.empty?
260
+ end
261
+
256
262
  def select_groups_from method, quantity
257
263
  selection = @context
258
264
  rows, indexes = [], []
@@ -293,6 +299,17 @@ module Daru
293
299
  end
294
300
  end
295
301
 
302
+ def resultant_context(multi_index_tuples, names)
303
+ multi_index = Daru::MultiIndex.from_tuples(multi_index_tuples)
304
+ context_tmp = @context.dup.delete_vectors(*names)
305
+ rows_tuples = context_tmp.access_row_tuples_by_indexs(
306
+ *@groups.values.flatten!
307
+ )
308
+ context_new = Daru::DataFrame.rows(rows_tuples, index: multi_index)
309
+ context_new.vectors = context_tmp.vectors
310
+ context_new
311
+ end
312
+
296
313
  def all_indices_for arry, element
297
314
  found, index, indexes = -1, -1, []
298
315
  while found
@@ -9,13 +9,13 @@ module Daru
9
9
  end
10
10
 
11
11
  def & other
12
- BoolArray.new @barry.zip(other.barry).map { |b, o| b && o }
12
+ BoolArray.new(@barry.zip(other.barry).map { |b, o| b && o })
13
13
  end
14
14
 
15
15
  alias :and :&
16
16
 
17
17
  def | other
18
- BoolArray.new @barry.zip(other.barry).map { |b, o| b || o }
18
+ BoolArray.new(@barry.zip(other.barry).map { |b, o| b || o })
19
19
  end
20
20
 
21
21
  alias :or :|
@@ -39,11 +39,11 @@ module Daru
39
39
 
40
40
  class << self
41
41
  def apply_scalar_operator operator, data, other
42
- BoolArray.new data.map { |d| !!d.send(operator, other) }
42
+ BoolArray.new(data.map { |d| !!d.send(operator, other) if d.respond_to?(operator) })
43
43
  end
44
44
 
45
45
  def apply_vector_operator operator, vector, other
46
- BoolArray.new vector.zip(other).map { |d, o| !!d.send(operator, o) }
46
+ BoolArray.new(vector.zip(other).map { |d, o| !!d.send(operator, o) })
47
47
  end
48
48
 
49
49
  def df_where data_frame, bool_array