daru 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +20 -7
- data/CONTRIBUTING.md +1 -1
- data/History.md +48 -1
- data/README.md +3 -3
- data/benchmarks/statistics.rb +6 -6
- data/benchmarks/where_clause.rb +1 -1
- data/benchmarks/where_vs_filter.rb +1 -1
- data/daru.gemspec +3 -2
- data/lib/daru.rb +14 -6
- data/lib/daru/accessors/gsl_wrapper.rb +1 -1
- data/lib/daru/accessors/nmatrix_wrapper.rb +2 -0
- data/lib/daru/category.rb +1 -1
- data/lib/daru/core/group_by.rb +32 -15
- data/lib/daru/core/query.rb +4 -4
- data/lib/daru/dataframe.rb +196 -48
- data/lib/daru/date_time/index.rb +7 -5
- data/lib/daru/formatters/table.rb +1 -0
- data/lib/daru/index/index.rb +121 -33
- data/lib/daru/index/multi_index.rb +83 -3
- data/lib/daru/io/csv/converters.rb +18 -0
- data/lib/daru/io/io.rb +80 -11
- data/lib/daru/io/sql_data_source.rb +10 -0
- data/lib/daru/iruby/templates/dataframe.html.erb +3 -50
- data/lib/daru/iruby/templates/dataframe_mi.html.erb +3 -56
- data/lib/daru/iruby/templates/dataframe_mi_tbody.html.erb +35 -0
- data/lib/daru/iruby/templates/dataframe_mi_thead.html.erb +21 -0
- data/lib/daru/iruby/templates/dataframe_tbody.html.erb +28 -0
- data/lib/daru/iruby/templates/dataframe_thead.html.erb +21 -0
- data/lib/daru/iruby/templates/vector.html.erb +3 -25
- data/lib/daru/iruby/templates/vector_mi.html.erb +3 -34
- data/lib/daru/iruby/templates/vector_mi_tbody.html.erb +26 -0
- data/lib/daru/iruby/templates/vector_mi_thead.html.erb +8 -0
- data/lib/daru/iruby/templates/vector_tbody.html.erb +17 -0
- data/lib/daru/iruby/templates/vector_thead.html.erb +8 -0
- data/lib/daru/maths/statistics/dataframe.rb +9 -11
- data/lib/daru/maths/statistics/vector.rb +139 -32
- data/lib/daru/plotting/gruff/dataframe.rb +13 -15
- data/lib/daru/plotting/nyaplot/category.rb +1 -1
- data/lib/daru/plotting/nyaplot/dataframe.rb +4 -4
- data/lib/daru/plotting/nyaplot/vector.rb +1 -2
- data/lib/daru/vector.rb +169 -80
- data/lib/daru/version.rb +1 -1
- data/spec/category_spec.rb +19 -19
- data/spec/core/group_by_spec.rb +47 -0
- data/spec/core/query_spec.rb +55 -50
- data/spec/daru_spec.rb +22 -0
- data/spec/dataframe_spec.rb +118 -6
- data/spec/date_time/index_spec.rb +34 -16
- data/spec/extensions/rserve_spec.rb +1 -1
- data/spec/fixtures/boolean_converter_test.csv +5 -0
- data/spec/fixtures/eciresults.html +394 -0
- data/spec/fixtures/empty_rows_test.csv +17 -0
- data/spec/fixtures/macau.html +3691 -0
- data/spec/fixtures/macd_data.csv +150 -0
- data/spec/fixtures/moneycontrol.html +6812 -0
- data/spec/fixtures/url_test.txt~ +0 -0
- data/spec/fixtures/valid_markup.html +62 -0
- data/spec/fixtures/wiki_climate.html +1243 -0
- data/spec/fixtures/wiki_table_info.html +631 -0
- data/spec/formatters/table_formatter_spec.rb +29 -0
- data/spec/index/categorical_index_spec.rb +33 -33
- data/spec/index/index_spec.rb +134 -41
- data/spec/index/multi_index_spec.rb +115 -31
- data/spec/io/io_spec.rb +201 -0
- data/spec/io/sql_data_source_spec.rb +31 -41
- data/spec/iruby/dataframe_spec.rb +17 -19
- data/spec/iruby/vector_spec.rb +26 -28
- data/spec/maths/statistics/vector_spec.rb +136 -14
- data/spec/plotting/gruff/category_spec.rb +3 -3
- data/spec/plotting/gruff/dataframe_spec.rb +14 -4
- data/spec/plotting/gruff/vector_spec.rb +9 -9
- data/spec/plotting/nyaplot/category_spec.rb +5 -9
- data/spec/plotting/nyaplot/dataframe_spec.rb +72 -47
- data/spec/plotting/nyaplot/vector_spec.rb +5 -11
- data/spec/shared/vector_display_spec.rb +12 -14
- data/spec/spec_helper.rb +21 -0
- data/spec/support/matchers.rb +5 -0
- data/spec/vector_spec.rb +222 -72
- metadata +68 -23
- data/spec/fixtures/stock_data.csv +0 -500
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10338f8d554cc2c70b2dcc2d8fd029e73446f4de
|
4
|
+
data.tar.gz: b848b5923eebe90577ef93d4c9e988d7aa09fe9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad6c0de4217a65a2c6245c4b969e98d970da47a08ce8128b060cd06a13ae415df6d5e7fdc7bba4c84115fc8559e80bea0a39c87efb1c3401df358f4df5d43117
|
7
|
+
data.tar.gz: 34abe4afd0c88c24d3d0bbd6f11df5efe554f50b0d3d045a8a969f4eae2232d8d1cfeead814e336da507ca94b3126447631699258fe1a5dc5ea736de77c587f8
|
data/.rubocop.yml
CHANGED
@@ -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
|
-
|
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
|
-
|
28
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
25
29
|
EnforcedStyle: no_space
|
26
30
|
|
27
|
-
|
31
|
+
Layout/SpaceInsideBlockBraces:
|
28
32
|
EnforcedStyle: space
|
29
33
|
|
30
|
-
|
34
|
+
Layout/SpaceInsideHashLiteralBraces:
|
31
35
|
EnforcedStyle: no_space
|
32
36
|
|
33
|
-
|
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
|
-
|
64
|
+
Layout/SpaceAfterComma:
|
61
65
|
Enabled: false
|
62
66
|
|
63
|
-
|
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
|
data/CONTRIBUTING.md
CHANGED
@@ -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/
|
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
|
|
data/benchmarks/statistics.rb
CHANGED
@@ -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
|
data/benchmarks/where_clause.rb
CHANGED
data/daru.gemspec
CHANGED
@@ -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', '
|
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
|
data/lib/daru.rb
CHANGED
@@ -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
|
-
|
89
|
+
{'spreadsheet' => '~>1.1.1', 'mechanize' => '~>2.7.5'}.each do |name, version|
|
84
90
|
begin
|
85
|
-
gem
|
86
|
-
require
|
91
|
+
gem name, version
|
92
|
+
require name
|
87
93
|
rescue LoadError
|
88
|
-
|
89
|
-
" #{
|
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'
|
@@ -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
|
data/lib/daru/category.rb
CHANGED
@@ -461,7 +461,7 @@ module Daru
|
|
461
461
|
@coding_scheme = scheme
|
462
462
|
end
|
463
463
|
|
464
|
-
CODING_SCHEMES = [
|
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=
|
data/lib/daru/core/group_by.rb
CHANGED
@@ -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
|
-
|
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:
|
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
|
data/lib/daru/core/query.rb
CHANGED
@@ -9,13 +9,13 @@ module Daru
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def & other
|
12
|
-
BoolArray.new
|
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
|
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
|
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
|
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
|