daru_lite 0.3.4 → 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.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +84 -0
  3. data/README.md +16 -1
  4. data/lib/daru_lite/category.rb +1 -1
  5. data/lib/daru_lite/core/group_by.rb +0 -4
  6. data/lib/daru_lite/core/merge.rb +2 -2
  7. data/lib/daru_lite/data_frame/calculatable.rb +12 -6
  8. data/lib/daru_lite/data_frame/duplicatable.rb +0 -14
  9. data/lib/daru_lite/data_frame/iterable.rb +2 -2
  10. data/lib/daru_lite/data_frame/missable.rb +0 -9
  11. data/lib/daru_lite/dataframe.rb +34 -9
  12. data/lib/daru_lite/date_time/index.rb +4 -4
  13. data/lib/daru_lite/index/multi_index.rb +1 -2
  14. data/lib/daru_lite/maths/statistics/dataframe.rb +2 -4
  15. data/lib/daru_lite/maths/statistics/vector.rb +3 -8
  16. data/lib/daru_lite/monkeys/array.rb +4 -0
  17. data/lib/daru_lite/monkeys/hash.rb +3 -0
  18. data/lib/daru_lite/monkeys/matrix.rb +3 -0
  19. data/lib/daru_lite/monkeys/range.rb +4 -0
  20. data/lib/daru_lite/vector/missable.rb +0 -55
  21. data/lib/daru_lite/vector/sortable.rb +2 -2
  22. data/lib/daru_lite/vector.rb +3 -9
  23. data/lib/daru_lite/version.rb +1 -1
  24. data/lib/daru_lite.rb +8 -10
  25. metadata +54 -287
  26. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  27. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  28. data/.github/dependabot.yml +0 -11
  29. data/.github/workflows/ci.yml +0 -33
  30. data/.gitignore +0 -10
  31. data/.rspec +0 -2
  32. data/.rubocop.yml +0 -27
  33. data/.rubocop_todo.yml +0 -139
  34. data/CONTRIBUTING.md +0 -47
  35. data/Gemfile +0 -2
  36. data/Rakefile +0 -69
  37. data/ReleasePolicy.md +0 -20
  38. data/benchmarks/TradeoffData.csv +0 -65
  39. data/benchmarks/csv_reading.rb +0 -22
  40. data/benchmarks/dataframe_creation.rb +0 -39
  41. data/benchmarks/db_loading.rb +0 -33
  42. data/benchmarks/duplicating.rb +0 -45
  43. data/benchmarks/group_by.rb +0 -32
  44. data/benchmarks/joining.rb +0 -52
  45. data/benchmarks/row_access.rb +0 -41
  46. data/benchmarks/row_assign.rb +0 -36
  47. data/benchmarks/sorting.rb +0 -51
  48. data/benchmarks/statistics.rb +0 -28
  49. data/benchmarks/vector_access.rb +0 -31
  50. data/benchmarks/vector_assign.rb +0 -42
  51. data/benchmarks/where_clause.rb +0 -48
  52. data/benchmarks/where_vs_filter.rb +0 -28
  53. data/daru_lite.gemspec +0 -54
  54. data/daru_lite_test-shm +0 -0
  55. data/daru_lite_test-wal +0 -0
  56. data/images/README.md +0 -5
  57. data/images/con0.png +0 -0
  58. data/images/con1.png +0 -0
  59. data/images/init0.png +0 -0
  60. data/images/init1.png +0 -0
  61. data/images/man0.png +0 -0
  62. data/images/man1.png +0 -0
  63. data/images/man2.png +0 -0
  64. data/images/man3.png +0 -0
  65. data/images/man4.png +0 -0
  66. data/images/man5.png +0 -0
  67. data/images/man6.png +0 -0
  68. data/lib/daru_lite/accessors/mdarray_wrapper.rb +0 -7
  69. data/lib/daru_lite/monkeys/m_d_array.rb +0 -7
  70. data/lib/daru_lite/monkeys/object.rb +0 -7
  71. data/profile/_base.rb +0 -23
  72. data/profile/df_to_a.rb +0 -10
  73. data/profile/filter.rb +0 -13
  74. data/profile/joining.rb +0 -13
  75. data/profile/sorting.rb +0 -12
  76. data/profile/vector_each_with_index.rb +0 -9
  77. data/profile/vector_new.rb +0 -9
  78. data/spec/accessors/array_wrapper_spec.rb +0 -3
  79. data/spec/category_spec.rb +0 -1767
  80. data/spec/core/group_by_spec.rb +0 -655
  81. data/spec/core/merge_spec.rb +0 -179
  82. data/spec/core/query_spec.rb +0 -347
  83. data/spec/daru_lite_spec.rb +0 -22
  84. data/spec/data_frame/aggregatable_example.rb +0 -65
  85. data/spec/data_frame/buildable_example.rb +0 -109
  86. data/spec/data_frame/calculatable_example.rb +0 -135
  87. data/spec/data_frame/convertible_example.rb +0 -180
  88. data/spec/data_frame/duplicatable_example.rb +0 -134
  89. data/spec/data_frame/fetchable_example.rb +0 -510
  90. data/spec/data_frame/filterable_example.rb +0 -456
  91. data/spec/data_frame/indexable_example.rb +0 -221
  92. data/spec/data_frame/iterable_example.rb +0 -481
  93. data/spec/data_frame/joinable_example.rb +0 -131
  94. data/spec/data_frame/missable_example.rb +0 -47
  95. data/spec/data_frame/pivotable_example.rb +0 -297
  96. data/spec/data_frame/queryable_example.rb +0 -92
  97. data/spec/data_frame/setable_example.rb +0 -513
  98. data/spec/data_frame/sortable_example.rb +0 -368
  99. data/spec/dataframe_spec.rb +0 -1342
  100. data/spec/date_time/data_spec.rb +0 -197
  101. data/spec/date_time/date_time_index_helper_spec.rb +0 -72
  102. data/spec/date_time/index_spec.rb +0 -588
  103. data/spec/date_time/offsets_spec.rb +0 -465
  104. data/spec/extensions/which_dsl_spec.rb +0 -38
  105. data/spec/fixtures/bank2.dat +0 -200
  106. data/spec/fixtures/boolean_converter_test.csv +0 -5
  107. data/spec/fixtures/countries.json +0 -7794
  108. data/spec/fixtures/duplicates.csv +0 -32
  109. data/spec/fixtures/eciresults.html +0 -394
  110. data/spec/fixtures/empties.dat +0 -2
  111. data/spec/fixtures/empty_rows_test.csv +0 -17
  112. data/spec/fixtures/macau.html +0 -3691
  113. data/spec/fixtures/macd_data.csv +0 -150
  114. data/spec/fixtures/matrix_test.csv +0 -100
  115. data/spec/fixtures/moneycontrol.html +0 -6812
  116. data/spec/fixtures/music_data.tsv +0 -2501
  117. data/spec/fixtures/repeated_fields.csv +0 -7
  118. data/spec/fixtures/sales-funnel.csv +0 -18
  119. data/spec/fixtures/scientific_notation.csv +0 -4
  120. data/spec/fixtures/string_converter_test.csv +0 -5
  121. data/spec/fixtures/strings.dat +0 -2
  122. data/spec/fixtures/test_xls.xls +0 -0
  123. data/spec/fixtures/test_xls_2.xls +0 -0
  124. data/spec/fixtures/url_test.txt~ +0 -0
  125. data/spec/fixtures/valid_markup.html +0 -62
  126. data/spec/fixtures/wiki_climate.html +0 -1243
  127. data/spec/fixtures/wiki_table_info.html +0 -631
  128. data/spec/formatters/table_formatter_spec.rb +0 -137
  129. data/spec/helpers_spec.rb +0 -8
  130. data/spec/index/categorical_index_spec.rb +0 -289
  131. data/spec/index/index_spec.rb +0 -438
  132. data/spec/index/multi_index_spec.rb +0 -752
  133. data/spec/io/io_spec.rb +0 -357
  134. data/spec/io/sql_data_source_spec.rb +0 -48
  135. data/spec/iruby/dataframe_spec.rb +0 -170
  136. data/spec/iruby/helpers_spec.rb +0 -49
  137. data/spec/iruby/multi_index_spec.rb +0 -37
  138. data/spec/iruby/vector_spec.rb +0 -105
  139. data/spec/maths/arithmetic/dataframe_spec.rb +0 -148
  140. data/spec/maths/arithmetic/vector_spec.rb +0 -165
  141. data/spec/maths/statistics/dataframe_spec.rb +0 -191
  142. data/spec/maths/statistics/vector_spec.rb +0 -756
  143. data/spec/monkeys_spec.rb +0 -42
  144. data/spec/shared/vector_display_spec.rb +0 -213
  145. data/spec/spec_helper.rb +0 -87
  146. data/spec/support/database_helper.rb +0 -29
  147. data/spec/support/matchers.rb +0 -5
  148. data/spec/vector/aggregatable_example.rb +0 -27
  149. data/spec/vector/calculatable_example.rb +0 -82
  150. data/spec/vector/convertible_example.rb +0 -126
  151. data/spec/vector/duplicatable_example.rb +0 -48
  152. data/spec/vector/fetchable_example.rb +0 -463
  153. data/spec/vector/filterable_example.rb +0 -165
  154. data/spec/vector/indexable_example.rb +0 -201
  155. data/spec/vector/iterable_example.rb +0 -111
  156. data/spec/vector/joinable_example.rb +0 -25
  157. data/spec/vector/missable_example.rb +0 -88
  158. data/spec/vector/queryable_example.rb +0 -91
  159. data/spec/vector/setable_example.rb +0 -300
  160. data/spec/vector/sortable_example.rb +0 -242
  161. data/spec/vector_spec.rb +0 -599
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f09114a32c50e38bfbf8d224919b444a820db2998e46443aa89a999fa856f8f5
4
- data.tar.gz: 0c27255f631de63d92d01b576cf42e3880e7453e8d20edfcda3969cea6f32ce3
3
+ metadata.gz: 8885d7275e768ead9f8f276cc9534d249b6f27fdf61f05c0657213d41cd2ff6b
4
+ data.tar.gz: b69d0a8ccb8b608fd2f1abb7dfad3d3f0ce05b1a45a31ce26b70b9a67acec986
5
5
  SHA512:
6
- metadata.gz: f9afdb5835447f5de2af1e7dba83592a8fb5dc4c6981f388609b3408386d03de69ad7a3382e53830d0636d522c462a2b43e988dd38336b67531d8a3ac2e4041a
7
- data.tar.gz: a47dfc18efa0b88bd6eaf1179b0cb9d6edf9e054124ee6606f857885862af7c2324c06d23dff4e8b585ff9084c394c8e5d1fb9c29a5f3a3e7b73374888ecac8a
6
+ metadata.gz: 0eb09f16cb373fed4ae1021cb75af88111c1f7c8113d0a49f3a46538937818c10cbe1259529a91ed94d6b89b72d20a1ce7b3bca412006eab74485ddf46b020d5
7
+ data.tar.gz: a7d62bdd41f6e6aeeffb5b532674cbf911c058584e3ce758fca7de3a3fe1f216004052caf82c132ff3b47b21fcf491d8ecd0e803ee921d12c30ed1a5d20d6c21
data/History.md CHANGED
@@ -1,3 +1,87 @@
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
+
25
+ # 0.3.5
26
+ * Declared `csv` and `matrix` as runtime dependencies
27
+ * Fixed `Vector#standardize`, `Vector#to_json` and `DataFrame#to_json` raising `NoMethodError` when ActiveSupport is not loaded
28
+ * Required Ruby 3.4 or later
29
+ * Stopped packaging specs, fixtures, benchmarks and images in the gem
30
+ * CI now runs on Ruby 3.4 and 4.0
31
+
32
+ # 0.3.4 (2026-07-20)
33
+ * Fixed latently-broken `CategoricalIndex` methods relying on `@relation_hash`
34
+ * Fixed DataFrame operations on a `MultiIndex` with duplicate tuples
35
+
36
+ # 0.3.3 (2026-07-01)
37
+ * Fixed `keep_vector_if` `TypeError` on a `MultiIndex` with duplicate tuples, preserving the vectors' index type
38
+
39
+ # 0.3.2 (2026-06-12)
40
+ * Fixed `NoMethodError` on single-key lookup with a `CategoricalIndex`
41
+
42
+ # 0.3.1 (2026-04-17)
43
+ * Raise `IndexError` on duplicate (row, column) pairs when using `crosstab_by_assignation`
44
+
45
+ # 0.3.0 (2026-04-14)
46
+ * Preserve `nil` rows when using `crosstab_by_assignation`
47
+
48
+ # 0.2.4 (2026-04-10)
49
+ * Updated rubocop and fixed offenses
50
+
51
+ # 0.2.3 (2026-03-27)
52
+ * Fixed regression when accessing a `MultiIndex` vector with an array among the arguments
53
+
54
+ # 0.2.2 (2026-03-27)
55
+ * Fixed regression when accessing a `MultiIndex` with an array among the arguments
56
+
57
+ # 0.2.1 (2026-03-26)
58
+ * Fixed `DataFrame#union` and row subsets via `#[]` when using a `MultiIndex`
59
+ * Dropped Code Climate
60
+
61
+ # 0.2.0 (2025-04-21)
62
+ * Updated dependencies
63
+ * [Breaking change] Dropped DBI
64
+ * [Security] Fixed polynomial ReDoS
65
+
66
+ # 0.1.3 (2024-09-09)
67
+ * Fixed `DataFrame#keep_row_if`, `Index#to_a` and `MultiIndex#delete_at`
68
+
69
+ # 0.1.2 (2024-09-05)
70
+ * Split the `DataFrame` and `Vector` classes into modules
71
+ * Fixed `rotate_vectors` with vectors of mixed classes
72
+ * Fixed `keep_row_if` for categorical indexes
73
+
74
+ # 0.1.1 (2024-02-26)
75
+ * First version of the daru Lite readme
76
+ * Fixed `inspect` when vector names are integers
77
+ * Fixed `order=` when vectors are of different classes
78
+
79
+ # 0.1.0 (2024-02-16)
80
+ * Renamed the gem to daru_lite
81
+ * Dropped gruff
82
+ * Added `DataFrame#rotate_vectors!` and `DataFrame#add_level_to_vectors`
83
+ * Added column to categorical index conversion
84
+
1
85
  # 0.0.1
2
86
  * Forked from Daru
3
87
  * Fixed incompatibilities with Ruby 3.1
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Simple, straightforward DataFrames for Ruby
4
4
 
5
- [![Build Status](https://github.com/pollandroll/daru_lite/actions/workflows/build.yml/badge.svg)](https://github.com/pollandroll/daru_lite/actions)
5
+ [![Build Status](https://github.com/pollandroll/daru_lite/actions/workflows/ci.yml/badge.svg)](https://github.com/pollandroll/daru_lite/actions)
6
6
  [![Gem Version](https://img.shields.io/gem/v/daru_lite.svg)](https://rubygems.org/gems/daru_lite)
7
7
 
8
8
  ## Introduction
@@ -115,6 +115,21 @@ data_frame.where(
115
115
  ```
116
116
  ![con1](images/con1.png)
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).
@@ -766,7 +766,7 @@ module DaruLite
766
766
  return if ordered?
767
767
 
768
768
  raise ArgumentError, "Can not apply #{operation} when vector is unordered. " \
769
- 'To make the categorical data ordered, use #ordered = true' \
769
+ 'To make the categorical data ordered, use #ordered = true'
770
770
  end
771
771
 
772
772
  def dummy_coding(full)
@@ -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)
@@ -110,11 +110,11 @@ module DaruLite
110
110
  end
111
111
 
112
112
  def row(lkey, rkey)
113
- # :nocov:
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
- # :nocov:
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 string with a calculation based
77
- # on vector.
76
+ # Returns a vector, based on a calculation on the vectors of the dataframe.
78
77
  #
79
- # The calculation will be eval'ed, so you can put any variable
80
- # or expression valid on ruby.
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("a+b")
85
+ # ds.compute { a + b }
87
86
  # => Vector [4,6]
88
- def compute(text, &block)
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
- # :nocov:
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
- # :nocov:
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
@@ -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 source, vectors_have_same_index
852
+ @data = clone_vectors columns, names, vectors_have_same_index
851
853
  else
852
- @data.concat source.values
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
- def clone_vectors(source, vectors_have_same_index)
868
- @vectors.map do |vector|
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
- source[vector].dup
897
+ column.dup.tap { |copy| copy.name = coerce_name(name) }
873
898
  else
874
- DaruLite::Vector.new([], name: vector, index: @index).tap do |v|
899
+ DaruLite::Vector.new([], name: coerce_name(name), index: @index).tap do |v|
875
900
  @index.each do |idx|
876
- v[idx] = source[vector].index.include?(idx) ? source[vector][idx] : nil
901
+ v[idx] = column.index.include?(idx) ? column[idx] : nil
877
902
  end
878
903
  end
879
904
  end
@@ -260,8 +260,8 @@ module DaruLite
260
260
  @offset =
261
261
  case opts[:freq]
262
262
  when :infer then Helper.infer_offset(data)
263
- when nil then nil
264
- else Helper.offset_from_frequency(opts[:freq])
263
+ when nil then nil
264
+ else Helper.offset_from_frequency(opts[:freq])
265
265
  end
266
266
 
267
267
  @frequency = @offset&.freq_string
@@ -472,7 +472,7 @@ module DaruLite
472
472
  _shift(-distance)
473
473
  end
474
474
 
475
- # :nocov:
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
- # :nocov:
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
- corr_arry = cov
157
- .to_matrix
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|
@@ -554,12 +549,12 @@ module DaruLite
554
549
  def standardize(use_population = false)
555
550
  m ||= mean
556
551
  sd = use_population ? sdp : sds
557
- return DaruLite::Vector.new([nil] * size) if m.nil? || sd.to_d == BigDecimal('0.0')
552
+ return DaruLite::Vector.new([nil] * size) if m.nil? || sd.nil? || sd.zero?
558
553
 
559
554
  vector_standardized_compute m, sd
560
555
  end
561
556
 
562
- # :nocov:
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
- # :nocov:
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,5 +1,8 @@
1
1
  class Matrix
2
2
  def elementwise_division(other)
3
+ DaruLite.deprecation_warning(
4
+ 'Matrix#elementwise_division will be removed in a future release, use Matrix#combine instead'
5
+ )
3
6
  map.with_index do |e, index|
4
7
  e / other.to_a.flatten[index]
5
8
  end
@@ -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
- # :nocov:
70
+ # simplecov:disable
71
71
  def sorted_data(&)
72
72
  @data.to_a.sort(&)
73
73
  end
74
- # :nocov:
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
@@ -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
- # :nocov:
541
+ # simplecov:disable
547
542
  def daru_lite_vector(*)
548
543
  self
549
544
  end
550
- # :nocov:
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 then DaruLite::Accessors::ArrayWrapper.new(source, self)
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
 
@@ -1,3 +1,3 @@
1
1
  module DaruLite
2
- VERSION = '0.3.4'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end