Skip to content

Commit

Permalink
Fix #add_row for DF with multi index (#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
zverok committed Oct 2, 2017
1 parent 32dd946 commit 8ef9a04
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ AllCops:
- 'vendor/**/*'
- 'benchmarks/*'
- 'profile/*'
- 'tmp/*'
DisplayCopNames: true
TargetRubyVersion: 2.0

Expand Down
2 changes: 1 addition & 1 deletion lib/daru/dataframe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ def []=(*args)
end

def add_row row, index=nil
self.row[index || @size] = row
self.row[*(index || @size)] = row
end

def add_vector n, vector
Expand Down
16 changes: 16 additions & 0 deletions spec/dataframe_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,22 @@
}
end

context 'with mulitiindex DF' do
subject(:data_frame) {
Daru::DataFrame.new({b: [11,12,13], a: [1,2,3],
c: [11,22,33]}, order: [:a, :b, :c],
index: Daru::MultiIndex.from_tuples([[:one, :two], [:one, :three], [:two, :four]]))
}

before { data_frame.add_row [100,200,300], [:two, :five] }

it { is_expected.to eq(Daru::DataFrame.new({
b: [11,12,13,200], a: [1,2,3,100],
c: [11,22,33,300]}, order: [:a, :b, :c],
index: Daru::MultiIndex.from_tuples([[:one, :two], [:one, :three], [:two, :four], [:two, :five]])))
}
end

it "allows adding rows after making empty DF by specfying only order" do
df = Daru::DataFrame.new({}, order: [:a, :b, :c])
df.add_row [1,2,3]
Expand Down

0 comments on commit 8ef9a04

Please sign in to comment.