daru_lite 0.3.5 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/History.md +24 -0
- data/README.md +15 -0
- data/lib/daru_lite/core/group_by.rb +0 -4
- data/lib/daru_lite/core/merge.rb +2 -2
- data/lib/daru_lite/data_frame/calculatable.rb +12 -6
- data/lib/daru_lite/data_frame/duplicatable.rb +0 -14
- data/lib/daru_lite/data_frame/iterable.rb +2 -2
- data/lib/daru_lite/data_frame/missable.rb +0 -9
- data/lib/daru_lite/dataframe.rb +34 -9
- data/lib/daru_lite/date_time/index.rb +2 -2
- data/lib/daru_lite/index/multi_index.rb +1 -2
- data/lib/daru_lite/maths/statistics/dataframe.rb +2 -4
- data/lib/daru_lite/maths/statistics/vector.rb +2 -7
- data/lib/daru_lite/monkeys/array.rb +4 -0
- data/lib/daru_lite/monkeys/hash.rb +3 -0
- data/lib/daru_lite/monkeys/matrix.rb +3 -0
- data/lib/daru_lite/monkeys/range.rb +4 -0
- data/lib/daru_lite/vector/missable.rb +0 -55
- data/lib/daru_lite/vector/sortable.rb +2 -2
- data/lib/daru_lite/vector.rb +3 -9
- data/lib/daru_lite/version.rb +1 -1
- data/lib/daru_lite.rb +7 -10
- metadata +5 -8
- data/lib/daru_lite/accessors/mdarray_wrapper.rb +0 -7
- data/lib/daru_lite/monkeys/m_d_array.rb +0 -7
- data/lib/daru_lite/monkeys/object.rb +0 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8885d7275e768ead9f8f276cc9534d249b6f27fdf61f05c0657213d41cd2ff6b
|
|
4
|
+
data.tar.gz: b69d0a8ccb8b608fd2f1abb7dfad3d3f0ce05b1a45a31ce26b70b9a67acec986
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0eb09f16cb373fed4ae1021cb75af88111c1f7c8113d0a49f3a46538937818c10cbe1259529a91ed94d6b89b72d20a1ce7b3bca412006eab74485ddf46b020d5
|
|
7
|
+
data.tar.gz: a7d62bdd41f6e6aeeffb5b532674cbf911c058584e3ce758fca7de3a3fe1f216004052caf82c132ff3b47b21fcf491d8ecd0e803ee921d12c30ed1a5d20d6c21
|
data/History.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
# 0.4.0
|
|
2
|
+
* [Breaking change] Removed the methods deprecated since 2016:
|
|
3
|
+
`Vector#has_missing_data?`, `#flawed?`, `#n_valid`, `#only_valid`, `#only_missing`, `#missing_positions` and `#freqs`,
|
|
4
|
+
`DataFrame#has_missing_data?`, `#flawed?` and `#dup_only_valid`. Use `#include_values?`, `#count_values`,
|
|
5
|
+
`#reject_values`, `#indexes` and `#frequencies` instead
|
|
6
|
+
* [Breaking change] Removed `DaruLite::Core::GroupBy.get_positions_group_map_on`, deprecated since 2019.
|
|
7
|
+
Use `DaruLite::Core::GroupBy.group_by_index_to_positions` instead
|
|
8
|
+
* [Breaking change] Removed the global `jruby?` method, the `MDArray` class (whose `#daru_lite_vector` and `#dv`
|
|
9
|
+
only raised `NotImplementedError`) and the `Object#itself` shim that daru Lite defined in every application
|
|
10
|
+
loading it
|
|
11
|
+
* [Breaking change] `Vector.new(dtype: :mdarray)` raises `ArgumentError` instead of `NotImplementedError`
|
|
12
|
+
* [Breaking change] `DataFrame.new` given a Hash of vectors, an `:order` and `clone: false` raises `ArgumentError`
|
|
13
|
+
when `:order` names a vector missing from the Hash (it used to relabel the vectors positionally) or lists
|
|
14
|
+
the same vector twice (it used to raise `IndexError`)
|
|
15
|
+
* Fixed vectors extracted from a DataFrame built from a Hash of vectors having the wrong name or no name:
|
|
16
|
+
they are now named after their column (#28)
|
|
17
|
+
* Fixed `DataFrame.new` with `clone: false` and an `:order` misaligning columns with their labels
|
|
18
|
+
* Deprecated `Array#daru_lite_vector`, `Array#dv`, `Array#to_index`, `Hash#daru_lite_vector`, `Hash#dv`,
|
|
19
|
+
`Range#daru_lite_vector`, `Range#dv`, `Range#to_index` and `Matrix#elementwise_division`.
|
|
20
|
+
They will be removed in a future release
|
|
21
|
+
* Deprecated `DataFrame#compute` with a String, which is `eval`'ed: pass a block instead.
|
|
22
|
+
`DataFrame#compute` can now be called with a block only
|
|
23
|
+
* Deprecation warnings use Ruby's `:deprecated` category: enable them with `Warning[:deprecated] = true` or `ruby -w`
|
|
24
|
+
|
|
1
25
|
# 0.3.5
|
|
2
26
|
* Declared `csv` and `matrix` as runtime dependencies
|
|
3
27
|
* Fixed `Vector#standardize`, `Vector#to_json` and `DataFrame#to_json` raising `NoMethodError` when ActiveSupport is not loaded
|
data/README.md
CHANGED
|
@@ -115,6 +115,21 @@ data_frame.where(
|
|
|
115
115
|
```
|
|
116
116
|

|
|
117
117
|
|
|
118
|
+
## Security
|
|
119
|
+
|
|
120
|
+
A few methods are not meant to receive untrusted input:
|
|
121
|
+
- `DataFrame#compute` with a String evaluates it as Ruby code. This form is deprecated, pass a block instead.
|
|
122
|
+
- `DaruLite::IO.load` and `Marshal.load` on any dumped daru Lite object (`DataFrame`, `Vector`, `DateTimeIndex`) can execute arbitrary code when the data is forged.
|
|
123
|
+
- `DataFrame.from_csv` opens any local path or HTTP(S) URL it is given.
|
|
124
|
+
|
|
125
|
+
## Deprecations
|
|
126
|
+
|
|
127
|
+
Deprecation warnings use Ruby's `:deprecated` category, which is silent by default. Turn them on before upgrading, with `ruby -w`, `RUBYOPT=-W:deprecated` or:
|
|
128
|
+
|
|
129
|
+
``` ruby
|
|
130
|
+
Warning[:deprecated] = true
|
|
131
|
+
```
|
|
132
|
+
|
|
118
133
|
## Documentation
|
|
119
134
|
|
|
120
135
|
Docs can be found [here](http://www.rubydoc.info/gems/daru_lite).
|
|
@@ -2,8 +2,6 @@ module DaruLite
|
|
|
2
2
|
module Core
|
|
3
3
|
class GroupBy
|
|
4
4
|
class << self
|
|
5
|
-
extend Gem::Deprecate
|
|
6
|
-
|
|
7
5
|
# @private
|
|
8
6
|
def group_by_index_to_positions(indexes_with_positions, sort: false)
|
|
9
7
|
index_to_positions = {}
|
|
@@ -19,8 +17,6 @@ module DaruLite
|
|
|
19
17
|
|
|
20
18
|
index_to_positions
|
|
21
19
|
end
|
|
22
|
-
alias get_positions_group_map_on group_by_index_to_positions
|
|
23
|
-
deprecate :get_positions_group_map_on, :group_by_index_to_positions, 2019, 10
|
|
24
20
|
|
|
25
21
|
# @private
|
|
26
22
|
def get_positions_group_for_aggregation(multi_index, level = -1)
|
data/lib/daru_lite/core/merge.rb
CHANGED
|
@@ -110,11 +110,11 @@ module DaruLite
|
|
|
110
110
|
end
|
|
111
111
|
|
|
112
112
|
def row(lkey, rkey)
|
|
113
|
-
# :
|
|
113
|
+
# simplecov:disable
|
|
114
114
|
# It's just an impossibility handler, can't be covered :)
|
|
115
115
|
raise 'Unexpected condition met during merge' if !lkey && !rkey
|
|
116
116
|
|
|
117
|
-
# :
|
|
117
|
+
# simplecov:enable
|
|
118
118
|
if lkey == rkey
|
|
119
119
|
self.merge_key = lkey
|
|
120
120
|
add_indicator(merge_matching_rows, :both)
|
|
@@ -73,21 +73,27 @@ module DaruLite
|
|
|
73
73
|
end
|
|
74
74
|
end
|
|
75
75
|
|
|
76
|
-
# Returns a vector, based on a
|
|
77
|
-
# on vector.
|
|
76
|
+
# Returns a vector, based on a calculation on the vectors of the dataframe.
|
|
78
77
|
#
|
|
79
|
-
# The
|
|
80
|
-
#
|
|
78
|
+
# The block is evaluated in the context of the dataframe, so vectors
|
|
79
|
+
# can be referred to by name.
|
|
81
80
|
#
|
|
82
81
|
# For example:
|
|
83
82
|
# a = DaruLite::Vector.new [1,2]
|
|
84
83
|
# b = DaruLite::Vector.new [3,4]
|
|
85
84
|
# ds = DaruLite::DataFrame.new({:a => a,:b => b})
|
|
86
|
-
# ds.compute
|
|
85
|
+
# ds.compute { a + b }
|
|
87
86
|
# => Vector [4,6]
|
|
88
|
-
|
|
87
|
+
#
|
|
88
|
+
# Passing the calculation as a String is deprecated: the String is
|
|
89
|
+
# eval'ed, which executes arbitrary code when it comes from user input.
|
|
90
|
+
def compute(text = nil, &block)
|
|
89
91
|
return instance_eval(&block) if block
|
|
92
|
+
raise ArgumentError, 'DataFrame#compute expects a block' if text.nil?
|
|
90
93
|
|
|
94
|
+
DaruLite.deprecation_warning(
|
|
95
|
+
'DataFrame#compute with a String will be removed in a future release, pass a block instead'
|
|
96
|
+
)
|
|
91
97
|
instance_eval(text)
|
|
92
98
|
end
|
|
93
99
|
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
module DaruLite
|
|
2
2
|
class DataFrame
|
|
3
3
|
module Duplicatable
|
|
4
|
-
extend Gem::Deprecate
|
|
5
|
-
|
|
6
4
|
# Duplicate the DataFrame entirely.
|
|
7
5
|
#
|
|
8
6
|
# == Arguments
|
|
@@ -53,18 +51,6 @@ module DaruLite
|
|
|
53
51
|
clone
|
|
54
52
|
end
|
|
55
53
|
end
|
|
56
|
-
|
|
57
|
-
# Creates a new duplicate dataframe containing only rows
|
|
58
|
-
# without a single missing value.
|
|
59
|
-
def dup_only_valid(vecs = nil)
|
|
60
|
-
rows_with_nil = @data.map { |vec| vec.indexes(*DaruLite::MISSING_VALUES) }
|
|
61
|
-
.inject(&:concat)
|
|
62
|
-
.uniq
|
|
63
|
-
|
|
64
|
-
row_indexes = @index.to_a
|
|
65
|
-
(vecs.nil? ? self : dup(vecs)).row[*(row_indexes - rows_with_nil)]
|
|
66
|
-
end
|
|
67
|
-
deprecate :dup_only_valid, :reject_values, 2016, 10
|
|
68
54
|
end
|
|
69
55
|
end
|
|
70
56
|
end
|
|
@@ -307,7 +307,7 @@ module DaruLite
|
|
|
307
307
|
# Generate a matrix, based on vector names of the DataFrame.
|
|
308
308
|
#
|
|
309
309
|
# @return {::Matrix}
|
|
310
|
-
# :
|
|
310
|
+
# simplecov:disable
|
|
311
311
|
# FIXME: Even not trying to cover this: I can't get, how it is expected
|
|
312
312
|
# to work.... -- zverok
|
|
313
313
|
def collect_matrix
|
|
@@ -322,7 +322,7 @@ module DaruLite
|
|
|
322
322
|
|
|
323
323
|
Matrix.rows(rows)
|
|
324
324
|
end
|
|
325
|
-
# :
|
|
325
|
+
# simplecov:enable
|
|
326
326
|
|
|
327
327
|
private
|
|
328
328
|
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
module DaruLite
|
|
2
2
|
class DataFrame
|
|
3
3
|
module Missable
|
|
4
|
-
extend Gem::Deprecate
|
|
5
|
-
|
|
6
4
|
# Rolling fillna
|
|
7
5
|
# replace all Float::NAN and NIL values with the preceeding or following value
|
|
8
6
|
#
|
|
@@ -63,13 +61,6 @@ module DaruLite
|
|
|
63
61
|
|
|
64
62
|
# TODO: remove next version
|
|
65
63
|
alias vector_missing_values missing_values_rows
|
|
66
|
-
|
|
67
|
-
def has_missing_data?
|
|
68
|
-
@data.any? { |vec| vec.include_values?(*DaruLite::MISSING_VALUES) }
|
|
69
|
-
end
|
|
70
|
-
alias flawed? has_missing_data?
|
|
71
|
-
deprecate :has_missing_data?, :include_values?, 2016, 10
|
|
72
|
-
deprecate :flawed?, :include_values?, 2016, 10
|
|
73
64
|
end
|
|
74
65
|
end
|
|
75
66
|
end
|
data/lib/daru_lite/dataframe.rb
CHANGED
|
@@ -42,8 +42,6 @@ module DaruLite
|
|
|
42
42
|
|
|
43
43
|
attr_accessor(*Configuration::INSPECT_OPTIONS_KEYS)
|
|
44
44
|
|
|
45
|
-
extend Gem::Deprecate
|
|
46
|
-
|
|
47
45
|
class << self
|
|
48
46
|
# Create DataFrame by specifying rows as an Array of Arrays or Array of
|
|
49
47
|
# DaruLite::Vector objects.
|
|
@@ -846,13 +844,38 @@ module DaruLite
|
|
|
846
844
|
|
|
847
845
|
@index = deduce_index index, source, vectors_have_same_index
|
|
848
846
|
|
|
847
|
+
# MultiIndex#to_a is costly: compute the column labels once.
|
|
848
|
+
names = @vectors.to_a
|
|
849
|
+
columns = source_vectors_for(source, names)
|
|
850
|
+
|
|
849
851
|
if clone
|
|
850
|
-
@data = clone_vectors
|
|
852
|
+
@data = clone_vectors columns, names, vectors_have_same_index
|
|
851
853
|
else
|
|
852
|
-
|
|
854
|
+
# Shared vectors are stored as is (never renamed: they belong to the caller), ordered by
|
|
855
|
+
# column label so @data stays parallel to @vectors.
|
|
856
|
+
validate_no_shared_duplicates names
|
|
857
|
+
@data.concat columns
|
|
853
858
|
end
|
|
854
859
|
end
|
|
855
860
|
|
|
861
|
+
def validate_no_shared_duplicates(names)
|
|
862
|
+
duplicates = names.tally.select { |_, count| count > 1 }.keys
|
|
863
|
+
return if duplicates.empty?
|
|
864
|
+
|
|
865
|
+
raise ArgumentError, 'clone: false cannot share one vector between duplicate columns: ' \
|
|
866
|
+
"#{duplicates.map(&:inspect).join(', ')}"
|
|
867
|
+
end
|
|
868
|
+
|
|
869
|
+
# Looks each column label up in the source exactly once, so the presence check and the read
|
|
870
|
+
# cannot disagree (e.g. a Hash resolving keys through a default proc).
|
|
871
|
+
def source_vectors_for(source, names)
|
|
872
|
+
columns = names.map { |name| source[name] }
|
|
873
|
+
missing = names.reject.with_index { |_, position| columns[position] }
|
|
874
|
+
return columns if missing.empty?
|
|
875
|
+
|
|
876
|
+
raise ArgumentError, ":order includes vectors not present in the source: #{missing.map(&:inspect).join(', ')}"
|
|
877
|
+
end
|
|
878
|
+
|
|
856
879
|
def deduce_index(index, source, vectors_have_same_index)
|
|
857
880
|
if !index.nil?
|
|
858
881
|
Index.coerce index
|
|
@@ -864,16 +887,18 @@ module DaruLite
|
|
|
864
887
|
end
|
|
865
888
|
end
|
|
866
889
|
|
|
867
|
-
|
|
868
|
-
|
|
890
|
+
# Each copy is named after its column label, so that extraction (df[:b], df[:a, :one]) returns
|
|
891
|
+
# a vector named after its column whatever the source vector was called.
|
|
892
|
+
def clone_vectors(columns, names, vectors_have_same_index)
|
|
893
|
+
columns.zip(names).map do |column, name|
|
|
869
894
|
# avoids matching indexes of vectors if all the supplied vectors
|
|
870
895
|
# have the same index.
|
|
871
896
|
if vectors_have_same_index
|
|
872
|
-
|
|
897
|
+
column.dup.tap { |copy| copy.name = coerce_name(name) }
|
|
873
898
|
else
|
|
874
|
-
DaruLite::Vector.new([], name:
|
|
899
|
+
DaruLite::Vector.new([], name: coerce_name(name), index: @index).tap do |v|
|
|
875
900
|
@index.each do |idx|
|
|
876
|
-
v[idx] =
|
|
901
|
+
v[idx] = column.index.include?(idx) ? column[idx] : nil
|
|
877
902
|
end
|
|
878
903
|
end
|
|
879
904
|
end
|
|
@@ -472,7 +472,7 @@ module DaruLite
|
|
|
472
472
|
_shift(-distance)
|
|
473
473
|
end
|
|
474
474
|
|
|
475
|
-
# :
|
|
475
|
+
# simplecov:disable
|
|
476
476
|
def _dump(_depth)
|
|
477
477
|
Marshal.dump(data: to_a, freq: @offset)
|
|
478
478
|
end
|
|
@@ -482,7 +482,7 @@ module DaruLite
|
|
|
482
482
|
|
|
483
483
|
DaruLite::DateTimeIndex.new(h[:data], freq: h[:freq])
|
|
484
484
|
end
|
|
485
|
-
# :
|
|
485
|
+
# simplecov:enable
|
|
486
486
|
|
|
487
487
|
# @!method year
|
|
488
488
|
# @return [Array<Integer>] Array containing year of each index.
|
|
@@ -82,6 +82,7 @@ module DaruLite
|
|
|
82
82
|
|
|
83
83
|
raise ArgumentError, 'Must specify both labels and levels' unless labels && levels
|
|
84
84
|
raise ArgumentError, 'Labels and levels should be same size' if labels.size != levels.size
|
|
85
|
+
raise ArgumentError, 'Must specify at least one level' if levels.empty?
|
|
85
86
|
raise ArgumentError, 'Incorrect labels and levels' if incorrect_fields?(labels, levels)
|
|
86
87
|
|
|
87
88
|
@labels = labels
|
|
@@ -95,8 +96,6 @@ module DaruLite
|
|
|
95
96
|
end
|
|
96
97
|
|
|
97
98
|
def incorrect_fields?(_labels, levels)
|
|
98
|
-
levels[0].size # FIXME: without this exact call some specs are failing
|
|
99
|
-
|
|
100
99
|
levels.any? { |e| e.uniq.size != e.size }
|
|
101
100
|
end
|
|
102
101
|
|
|
@@ -153,10 +153,8 @@ module DaruLite
|
|
|
153
153
|
# Calculate the correlation between the numeric vectors.
|
|
154
154
|
def correlation
|
|
155
155
|
standard_deviation = std.to_matrix
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
.elementwise_division(standard_deviation.transpose *
|
|
159
|
-
standard_deviation).to_a
|
|
156
|
+
deviation_products = standard_deviation.transpose * standard_deviation
|
|
157
|
+
corr_arry = cov.to_matrix.combine(deviation_products) { |covariance, product| covariance / product }.to_a
|
|
160
158
|
|
|
161
159
|
DaruLite::DataFrame.rows(corr_arry, index: numeric_vectors, order: numeric_vectors)
|
|
162
160
|
end
|
|
@@ -5,8 +5,6 @@ module DaruLite
|
|
|
5
5
|
# the computationally intensive tasks.
|
|
6
6
|
module Statistics
|
|
7
7
|
module Vector # rubocop:disable Metrics/ModuleLength
|
|
8
|
-
extend Gem::Deprecate
|
|
9
|
-
|
|
10
8
|
def mean
|
|
11
9
|
@data.mean
|
|
12
10
|
end
|
|
@@ -369,9 +367,6 @@ module DaruLite
|
|
|
369
367
|
)
|
|
370
368
|
end
|
|
371
369
|
|
|
372
|
-
alias freqs frequencies
|
|
373
|
-
deprecate :freqs, :frequencies, 2016, 10
|
|
374
|
-
|
|
375
370
|
def proportions
|
|
376
371
|
len = size - count_values(*DaruLite::MISSING_VALUES)
|
|
377
372
|
frequencies.to_h.transform_values do |count|
|
|
@@ -559,7 +554,7 @@ module DaruLite
|
|
|
559
554
|
vector_standardized_compute m, sd
|
|
560
555
|
end
|
|
561
556
|
|
|
562
|
-
# :
|
|
557
|
+
# simplecov:disable
|
|
563
558
|
def box_cox_transformation(lambda) # :nodoc:
|
|
564
559
|
must_be_numeric!
|
|
565
560
|
|
|
@@ -573,7 +568,7 @@ module DaruLite
|
|
|
573
568
|
end
|
|
574
569
|
end
|
|
575
570
|
end
|
|
576
|
-
# :
|
|
571
|
+
# simplecov:enable
|
|
577
572
|
|
|
578
573
|
# Replace each non-nil value in the vector with its percentile.
|
|
579
574
|
def vector_percentile
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
class Array
|
|
2
2
|
def daru_lite_vector(name = nil, index = nil, dtype = :array)
|
|
3
|
+
DaruLite.deprecation_warning(
|
|
4
|
+
'Array#daru_lite_vector and Array#dv will be removed in a future release, use DaruLite::Vector.new instead'
|
|
5
|
+
)
|
|
3
6
|
DaruLite::Vector.new self, name: name, index: index, dtype: dtype
|
|
4
7
|
end
|
|
5
8
|
|
|
6
9
|
alias dv daru_lite_vector
|
|
7
10
|
|
|
8
11
|
def to_index
|
|
12
|
+
DaruLite.deprecation_warning('Array#to_index will be removed in a future release, use DaruLite::Index.new instead')
|
|
9
13
|
DaruLite::Index.new self
|
|
10
14
|
end
|
|
11
15
|
end
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
class Hash
|
|
2
2
|
def daru_lite_vector(index = nil, dtype = :array)
|
|
3
|
+
DaruLite.deprecation_warning(
|
|
4
|
+
'Hash#daru_lite_vector and Hash#dv will be removed in a future release, use DaruLite::Vector.new instead'
|
|
5
|
+
)
|
|
3
6
|
DaruLite::Vector.new values[0], name: keys[0], index: index, dtype: dtype
|
|
4
7
|
end
|
|
5
8
|
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
class Range
|
|
2
2
|
def daru_lite_vector(name = nil, index = nil, dtype = :array)
|
|
3
|
+
DaruLite.deprecation_warning(
|
|
4
|
+
'Range#daru_lite_vector and Range#dv will be removed in a future release, use DaruLite::Vector.new instead'
|
|
5
|
+
)
|
|
3
6
|
DaruLite::Vector.new self, name: name, index: index, dtype: dtype
|
|
4
7
|
end
|
|
5
8
|
|
|
6
9
|
alias dv daru_lite_vector
|
|
7
10
|
|
|
8
11
|
def to_index
|
|
12
|
+
DaruLite.deprecation_warning('Range#to_index will be removed in a future release, use DaruLite::Index.new instead')
|
|
9
13
|
DaruLite::Index.new to_a
|
|
10
14
|
end
|
|
11
15
|
end
|
|
@@ -1,16 +1,6 @@
|
|
|
1
1
|
module DaruLite
|
|
2
2
|
class Vector
|
|
3
3
|
module Missable
|
|
4
|
-
extend Gem::Deprecate
|
|
5
|
-
|
|
6
|
-
# Reports whether missing data is present in the Vector.
|
|
7
|
-
def has_missing_data? # rubocop:disable Naming/PredicatePrefix
|
|
8
|
-
!indexes(*DaruLite::MISSING_VALUES).empty?
|
|
9
|
-
end
|
|
10
|
-
alias flawed? has_missing_data?
|
|
11
|
-
deprecate :has_missing_data?, :include_values?, 2016, 10
|
|
12
|
-
deprecate :flawed?, :include_values?, 2016, 10
|
|
13
|
-
|
|
14
4
|
# Replace all nils in the vector with the value passed as an argument. Destructive.
|
|
15
5
|
# See #replace_nils for non-destructive version
|
|
16
6
|
#
|
|
@@ -68,51 +58,6 @@ module DaruLite
|
|
|
68
58
|
dup.replace_nils!(replacement)
|
|
69
59
|
end
|
|
70
60
|
|
|
71
|
-
# number of non-missing elements
|
|
72
|
-
def n_valid
|
|
73
|
-
size - indexes(*DaruLite::MISSING_VALUES).size
|
|
74
|
-
end
|
|
75
|
-
deprecate :n_valid, :count_values, 2016, 10
|
|
76
|
-
|
|
77
|
-
# Creates a new vector consisting only of non-nil data
|
|
78
|
-
#
|
|
79
|
-
# == Arguments
|
|
80
|
-
#
|
|
81
|
-
# @param as_a [Symbol] Passing :array will return only the elements
|
|
82
|
-
# as an Array. Otherwise will return a DaruLite::Vector.
|
|
83
|
-
#
|
|
84
|
-
# @param _duplicate [Symbol] In case no missing data is found in the
|
|
85
|
-
# vector, setting this to false will return the same vector.
|
|
86
|
-
# Otherwise, a duplicate will be returned irrespective of
|
|
87
|
-
# presence of missing data.
|
|
88
|
-
|
|
89
|
-
def only_valid(as_a = :vector, _duplicate = true) # rubocop:disable Style/OptionalBooleanParameter
|
|
90
|
-
# FIXME: Now duplicate is just ignored.
|
|
91
|
-
# There are no spec that fail on this case, so I'll leave it
|
|
92
|
-
# this way for now - zverok, 2016-05-07
|
|
93
|
-
|
|
94
|
-
new_index = @index.to_a - indexes(*DaruLite::MISSING_VALUES)
|
|
95
|
-
new_vector = new_index.map { |idx| self[idx] }
|
|
96
|
-
|
|
97
|
-
if as_a == :vector
|
|
98
|
-
DaruLite::Vector.new new_vector, index: new_index, name: @name, dtype: dtype
|
|
99
|
-
else
|
|
100
|
-
new_vector
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
deprecate :only_valid, :reject_values, 2016, 10
|
|
104
|
-
|
|
105
|
-
# Returns a Vector containing only missing data (preserves indexes).
|
|
106
|
-
def only_missing(as_a = :vector)
|
|
107
|
-
case as_a
|
|
108
|
-
when :vector
|
|
109
|
-
self[*indexes(*DaruLite::MISSING_VALUES)]
|
|
110
|
-
when :array
|
|
111
|
-
self[*indexes(*DaruLite::MISSING_VALUES)].to_a
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
deprecate :only_missing, nil, 2016, 10
|
|
115
|
-
|
|
116
61
|
private
|
|
117
62
|
|
|
118
63
|
# Helper method returning validity of arbitrary value
|
|
@@ -67,11 +67,11 @@ module DaruLite
|
|
|
67
67
|
|
|
68
68
|
# Just sort the data and get an Array in return using Enumerable#sort.
|
|
69
69
|
# Non-destructive.
|
|
70
|
-
# :
|
|
70
|
+
# simplecov:disable
|
|
71
71
|
def sorted_data(&)
|
|
72
72
|
@data.to_a.sort(&)
|
|
73
73
|
end
|
|
74
|
-
# :
|
|
74
|
+
# simplecov:enable
|
|
75
75
|
|
|
76
76
|
# Reorder the vector with given positions
|
|
77
77
|
# @note Unlike #reindex! which takes index as input, it takes
|
data/lib/daru_lite/vector.rb
CHANGED
|
@@ -34,7 +34,6 @@ module DaruLite
|
|
|
34
34
|
include DaruLite::Vector::Setable
|
|
35
35
|
include DaruLite::Vector::Sortable
|
|
36
36
|
include DaruLite::Vector::Queryable
|
|
37
|
-
extend Gem::Deprecate
|
|
38
37
|
|
|
39
38
|
class << self
|
|
40
39
|
# Create a new vector by specifying the size and an optional value
|
|
@@ -123,10 +122,6 @@ module DaruLite
|
|
|
123
122
|
# The underlying dtype of the Vector. Can be :array.
|
|
124
123
|
attr_reader :dtype
|
|
125
124
|
attr_reader :nm_dtype
|
|
126
|
-
# An Array or the positions in the vector that are being treated as 'missing'.
|
|
127
|
-
attr_reader :missing_positions
|
|
128
|
-
|
|
129
|
-
deprecate :missing_positions, :indexes, 2016, 10
|
|
130
125
|
# Store a hash of labels for values. Supplementary only. Recommend using index
|
|
131
126
|
# for proper usage.
|
|
132
127
|
attr_accessor :labels
|
|
@@ -543,11 +538,11 @@ module DaruLite
|
|
|
543
538
|
)
|
|
544
539
|
end
|
|
545
540
|
|
|
546
|
-
# :
|
|
541
|
+
# simplecov:disable
|
|
547
542
|
def daru_lite_vector(*)
|
|
548
543
|
self
|
|
549
544
|
end
|
|
550
|
-
# :
|
|
545
|
+
# simplecov:enable
|
|
551
546
|
|
|
552
547
|
alias dv daru_lite_vector
|
|
553
548
|
|
|
@@ -659,8 +654,7 @@ module DaruLite
|
|
|
659
654
|
|
|
660
655
|
new_vector =
|
|
661
656
|
case dtype
|
|
662
|
-
when :array
|
|
663
|
-
when :mdarray then raise NotImplementedError, 'MDArray not yet supported.'
|
|
657
|
+
when :array then DaruLite::Accessors::ArrayWrapper.new(source, self)
|
|
664
658
|
else raise ArgumentError, "Unknown dtype #{dtype}"
|
|
665
659
|
end
|
|
666
660
|
|
data/lib/daru_lite/version.rb
CHANGED
data/lib/daru_lite.rb
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
# :nocov:
|
|
2
|
-
def jruby?
|
|
3
|
-
RUBY_ENGINE == 'jruby'
|
|
4
|
-
end
|
|
5
|
-
# :nocov:
|
|
6
|
-
|
|
7
1
|
module DaruLite
|
|
8
2
|
DAYS_OF_WEEK = {
|
|
9
3
|
'SUN' => 0,
|
|
@@ -53,9 +47,9 @@ module DaruLite
|
|
|
53
47
|
require library.to_s
|
|
54
48
|
class_variable_set(cv, true)
|
|
55
49
|
rescue LoadError
|
|
56
|
-
# :
|
|
50
|
+
# simplecov:disable
|
|
57
51
|
class_variable_set(cv, false)
|
|
58
|
-
# :
|
|
52
|
+
# simplecov:enable
|
|
59
53
|
end
|
|
60
54
|
end
|
|
61
55
|
class_variable_get(cv)
|
|
@@ -65,6 +59,11 @@ module DaruLite
|
|
|
65
59
|
def error(msg)
|
|
66
60
|
error_stream&.puts msg
|
|
67
61
|
end
|
|
62
|
+
|
|
63
|
+
# Emits a warning of the :deprecated category, attributed to the caller of the deprecated method.
|
|
64
|
+
def deprecation_warning(message)
|
|
65
|
+
warn "[DaruLite] DEPRECATION: #{message}", uplevel: 2, category: :deprecated
|
|
66
|
+
end
|
|
68
67
|
end
|
|
69
68
|
end
|
|
70
69
|
|
|
@@ -93,9 +92,7 @@ require 'daru_lite/exceptions'
|
|
|
93
92
|
|
|
94
93
|
require 'daru_lite/monkeys/array'
|
|
95
94
|
require 'daru_lite/monkeys/hash'
|
|
96
|
-
require 'daru_lite/monkeys/m_d_array'
|
|
97
95
|
require 'daru_lite/monkeys/matrix'
|
|
98
|
-
require 'daru_lite/monkeys/object'
|
|
99
96
|
require 'daru_lite/monkeys/range'
|
|
100
97
|
|
|
101
98
|
require 'daru_lite/core/group_by'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: daru_lite
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Thomas Naude-Filonnière
|
|
@@ -215,28 +215,28 @@ dependencies:
|
|
|
215
215
|
requirements:
|
|
216
216
|
- - "~>"
|
|
217
217
|
- !ruby/object:Gem::Version
|
|
218
|
-
version: '
|
|
218
|
+
version: '2.0'
|
|
219
219
|
type: :development
|
|
220
220
|
prerelease: false
|
|
221
221
|
version_requirements: !ruby/object:Gem::Requirement
|
|
222
222
|
requirements:
|
|
223
223
|
- - "~>"
|
|
224
224
|
- !ruby/object:Gem::Version
|
|
225
|
-
version: '
|
|
225
|
+
version: '2.0'
|
|
226
226
|
- !ruby/object:Gem::Dependency
|
|
227
227
|
name: simplecov
|
|
228
228
|
requirement: !ruby/object:Gem::Requirement
|
|
229
229
|
requirements:
|
|
230
230
|
- - "~>"
|
|
231
231
|
- !ruby/object:Gem::Version
|
|
232
|
-
version: '
|
|
232
|
+
version: '1.3'
|
|
233
233
|
type: :development
|
|
234
234
|
prerelease: false
|
|
235
235
|
version_requirements: !ruby/object:Gem::Requirement
|
|
236
236
|
requirements:
|
|
237
237
|
- - "~>"
|
|
238
238
|
- !ruby/object:Gem::Version
|
|
239
|
-
version: '
|
|
239
|
+
version: '1.3'
|
|
240
240
|
- !ruby/object:Gem::Dependency
|
|
241
241
|
name: simplecov_json_formatter
|
|
242
242
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -309,7 +309,6 @@ files:
|
|
|
309
309
|
- lib/daru_lite.rb
|
|
310
310
|
- lib/daru_lite/accessors/array_wrapper.rb
|
|
311
311
|
- lib/daru_lite/accessors/dataframe_by_row.rb
|
|
312
|
-
- lib/daru_lite/accessors/mdarray_wrapper.rb
|
|
313
312
|
- lib/daru_lite/category.rb
|
|
314
313
|
- lib/daru_lite/configuration.rb
|
|
315
314
|
- lib/daru_lite/core/group_by.rb
|
|
@@ -363,9 +362,7 @@ files:
|
|
|
363
362
|
- lib/daru_lite/maths/statistics/vector.rb
|
|
364
363
|
- lib/daru_lite/monkeys/array.rb
|
|
365
364
|
- lib/daru_lite/monkeys/hash.rb
|
|
366
|
-
- lib/daru_lite/monkeys/m_d_array.rb
|
|
367
365
|
- lib/daru_lite/monkeys/matrix.rb
|
|
368
|
-
- lib/daru_lite/monkeys/object.rb
|
|
369
366
|
- lib/daru_lite/monkeys/range.rb
|
|
370
367
|
- lib/daru_lite/vector.rb
|
|
371
368
|
- lib/daru_lite/vector/aggregatable.rb
|