daru_lite 0.3.0 → 0.3.2
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/lib/daru_lite/dataframe.rb +8 -0
- data/lib/daru_lite/index/categorical_index.rb +16 -0
- data/lib/daru_lite/version.rb +1 -1
- data/spec/dataframe_spec.rb +27 -0
- data/spec/index/categorical_index_spec.rb +32 -0
- metadata +3 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f72d838a7ae6b15ca8d5d4d2942f733ee731815a432dec1b76e51296cd7d5fe7
|
|
4
|
+
data.tar.gz: 5653ee135b2fcf671eb28ad8af54cb11e1d8d6187bdfdef284d425b23d0da290
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b3780b06dcb392bd866af2424ea0a19ddf263cb125b13092c3d6674ab8d6d1c576bbf6b78e6bfb794cc21aac73ac1f1af4faacb0905196c6cfb5a5190be56455
|
|
7
|
+
data.tar.gz: 4e39865f597bf9ecb63270c9f6df963ad4e8bdf6fecda6de0a305fb81b5c81b58787e28267a7e84644194a4bd63442e98fb56f642c03ef327e08b888210637ca
|
data/lib/daru_lite/dataframe.rb
CHANGED
|
@@ -89,6 +89,7 @@ module DaruLite
|
|
|
89
89
|
data = Hash.new do |h, col|
|
|
90
90
|
h[col] = row_index.map { |r| [r, nil] }.to_h
|
|
91
91
|
end
|
|
92
|
+
validate_no_duplicate_pairs(rows, columns)
|
|
92
93
|
columns.zip(rows, values).each { |c, r, v| data[c][r] = v }
|
|
93
94
|
|
|
94
95
|
# FIXME: in fact, WITHOUT this line you'll obtain more "right"
|
|
@@ -101,6 +102,13 @@ module DaruLite
|
|
|
101
102
|
|
|
102
103
|
private
|
|
103
104
|
|
|
105
|
+
def validate_no_duplicate_pairs(rows, columns)
|
|
106
|
+
seen = Set.new
|
|
107
|
+
columns.to_a.zip(rows.to_a).each do |pair|
|
|
108
|
+
raise IndexError, "Duplicate (column, row) pair: #{pair.inspect}" unless seen.add?(pair)
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
104
112
|
def guess_order(source)
|
|
105
113
|
case source.first
|
|
106
114
|
when Vector # assume that all are Vectors
|
|
@@ -65,6 +65,22 @@ module DaruLite
|
|
|
65
65
|
positions.size == 1 ? positions.first : positions.sort
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
+
# Returns the position(s) of the given category/categories or position(s).
|
|
69
|
+
# Mirrors Index#[] but resolves against the categorical structure
|
|
70
|
+
# (@cat_hash / @array) instead of @relation_hash, which CategoricalIndex
|
|
71
|
+
# never populates.
|
|
72
|
+
# @param keys [Array<object>] categories or positions to look up
|
|
73
|
+
# @return [Integer, Array<Integer>, nil] position(s), or nil if absent
|
|
74
|
+
# @example
|
|
75
|
+
# idx = DaruLite::CategoricalIndex.new [:a, :b, :a]
|
|
76
|
+
# idx[:b] # => 1
|
|
77
|
+
# idx[:z] # => nil
|
|
78
|
+
def [](*keys)
|
|
79
|
+
pos(*keys)
|
|
80
|
+
rescue IndexError
|
|
81
|
+
nil
|
|
82
|
+
end
|
|
83
|
+
|
|
68
84
|
# Returns index value from position
|
|
69
85
|
# @param pos [Integer] the position to look for
|
|
70
86
|
# @return [object] category corresponding to position
|
data/lib/daru_lite/version.rb
CHANGED
data/spec/dataframe_spec.rb
CHANGED
|
@@ -886,6 +886,23 @@ describe DaruLite::DataFrame do
|
|
|
886
886
|
expect(df).to eq(DaruLite::DataFrame.new({b: [11,12,14,15], a: [1,2,4,5],
|
|
887
887
|
c: [11,22,44,55]}, order: [:a, :b, :c], index: [:one, :two, :four, :five]))
|
|
888
888
|
end
|
|
889
|
+
|
|
890
|
+
context "when the data frame has a CategoricalIndex" do
|
|
891
|
+
let(:categorical_df) do
|
|
892
|
+
frame = DaruLite::DataFrame.new(
|
|
893
|
+
{ a: [1, 2, 3], b: [11, 22, 33] },
|
|
894
|
+
order: [:a, :b],
|
|
895
|
+
index: [:base, :one, :two]
|
|
896
|
+
)
|
|
897
|
+
frame.index = DaruLite::CategoricalIndex.new([:base, :one, :two])
|
|
898
|
+
frame
|
|
899
|
+
end
|
|
900
|
+
|
|
901
|
+
it "deletes the specified row without raising" do
|
|
902
|
+
expect { categorical_df.delete_row :base }.not_to raise_error
|
|
903
|
+
expect(categorical_df.index.to_a).to eq [:one, :two]
|
|
904
|
+
end
|
|
905
|
+
end
|
|
889
906
|
end
|
|
890
907
|
|
|
891
908
|
context "#rename_vectors!" do
|
|
@@ -1087,6 +1104,16 @@ describe DaruLite::DataFrame do
|
|
|
1087
1104
|
expect(df['x'].to_a).to eq([1, 2])
|
|
1088
1105
|
expect(df['y'].to_a).to eq([3, 4])
|
|
1089
1106
|
end
|
|
1107
|
+
|
|
1108
|
+
it 'raises IndexError when given duplicate (row, column) pairs' do
|
|
1109
|
+
rows = DaruLite::Vector.new(%w[a a b])
|
|
1110
|
+
columns = DaruLite::Vector.new(%w[x x y])
|
|
1111
|
+
values = DaruLite::Vector.new([1, 2, 3])
|
|
1112
|
+
|
|
1113
|
+
expect {
|
|
1114
|
+
described_class.crosstab_by_assignation(rows, columns, values)
|
|
1115
|
+
}.to raise_error(IndexError, /Duplicate/)
|
|
1116
|
+
end
|
|
1090
1117
|
end
|
|
1091
1118
|
|
|
1092
1119
|
context '#inspect' do
|
|
@@ -68,6 +68,38 @@ describe DaruLite::CategoricalIndex do
|
|
|
68
68
|
end
|
|
69
69
|
end
|
|
70
70
|
|
|
71
|
+
describe "#[]" do
|
|
72
|
+
context "when the category occurs once" do
|
|
73
|
+
subject { index[:b] }
|
|
74
|
+
|
|
75
|
+
it { is_expected.to eq 1 }
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
context "when the category occurs multiple times" do
|
|
79
|
+
subject { index[:a] }
|
|
80
|
+
|
|
81
|
+
it { is_expected.to eq [0, 2, 3] }
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
context "when given a positional index" do
|
|
85
|
+
subject { index[0] }
|
|
86
|
+
|
|
87
|
+
it { is_expected.to eq 0 }
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
context "when given multiple categories" do
|
|
91
|
+
subject { index[:a, :c] }
|
|
92
|
+
|
|
93
|
+
it { is_expected.to eq [0, 2, 3, 4] }
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
context "when the category is absent" do
|
|
97
|
+
subject { index[:z] }
|
|
98
|
+
|
|
99
|
+
it { is_expected.to be_nil }
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
71
103
|
context "#subset" do
|
|
72
104
|
let(:idx) { described_class.new [:a, 1, :a, 1, :c] }
|
|
73
105
|
|
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.3.
|
|
4
|
+
version: 0.3.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Thomas Naude-Filonnière
|
|
@@ -9,10 +9,9 @@ authors:
|
|
|
9
9
|
- Julie Thomas
|
|
10
10
|
- Amar Slaoua
|
|
11
11
|
- Mourtada Belhantri
|
|
12
|
-
autorequire:
|
|
13
12
|
bindir: bin
|
|
14
13
|
cert_chain: []
|
|
15
|
-
date:
|
|
14
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
16
15
|
dependencies:
|
|
17
16
|
- !ruby/object:Gem::Dependency
|
|
18
17
|
name: activerecord
|
|
@@ -317,7 +316,6 @@ description: |
|
|
|
317
316
|
and can be used with many others like mixed_models, gnuplotrb and iruby.
|
|
318
317
|
|
|
319
318
|
Daru Lite is a fork of Daru that aims to focus on data manipulation and stability.
|
|
320
|
-
email:
|
|
321
319
|
executables: []
|
|
322
320
|
extensions: []
|
|
323
321
|
extra_rdoc_files: []
|
|
@@ -538,7 +536,6 @@ homepage: https://github.com/pollandroll/daru
|
|
|
538
536
|
licenses:
|
|
539
537
|
- BSD-2-Clause
|
|
540
538
|
metadata: {}
|
|
541
|
-
post_install_message:
|
|
542
539
|
rdoc_options: []
|
|
543
540
|
require_paths:
|
|
544
541
|
- lib
|
|
@@ -553,8 +550,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
553
550
|
- !ruby/object:Gem::Version
|
|
554
551
|
version: '0'
|
|
555
552
|
requirements: []
|
|
556
|
-
rubygems_version:
|
|
557
|
-
signing_key:
|
|
553
|
+
rubygems_version: 4.0.9
|
|
558
554
|
specification_version: 4
|
|
559
555
|
summary: Data Analysis in RUby, stripped down
|
|
560
556
|
test_files:
|