Skip to content

Commit

Permalink
DataFrame#vectors= should change the name of the vectors in @data. (#…
Browse files Browse the repository at this point in the history
…293)

* create test

* DataFrame#vector= changes the name of vectors in @DaTa
  • Loading branch information
genya0407 authored and v0dro committed Jan 28, 2017
1 parent e395626 commit cedab19
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/daru/dataframe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,9 @@ def vectors= new_index
end

@vectors = new_index
@data.zip(new_index.to_a).each do |vect, name|
vect.name = name
end
self
end

Expand Down
7 changes: 7 additions & 0 deletions spec/dataframe_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2594,6 +2594,13 @@
@df.vectors = Daru::Index.new([1,2,'3',4,'5'])
}.to raise_error(ArgumentError)
end

it "change name of vectors in @data" do
new_index_array = [:k, :l, :m]
@df.vectors = Daru::Index.new(new_index_array)

expect(@df.data.map { |vector| vector.name }).to eq(new_index_array)
end
end

context "#rename_vectors" do
Expand Down

0 comments on commit cedab19

Please sign in to comment.