Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataFrame#vectors= should change the name of the vectors in @data. #293

Merged
merged 2 commits into from
Jan 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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