Skip to content

Commit

Permalink
Fix to_s when name is a symbol #381 (#383)
Browse files Browse the repository at this point in the history
* Fix to_s when name is a symbol

* Add spec for breaking case
  • Loading branch information
baarkerlounger authored and v0dro committed Aug 9, 2017
1 parent a46949f commit 843a2ef
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/daru/dataframe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1902,7 +1902,7 @@ def to_html_tbody(threshold=30)
end

def to_s
"#<#{self.class}#{': ' + @name if @name}(#{nrows}x#{ncols})>"
"#<#{self.class}#{': ' + @name.to_s if @name}(#{nrows}x#{ncols})>"
end

# Method for updating the metadata (i.e. missing value positions) of the
Expand Down
2 changes: 1 addition & 1 deletion lib/daru/vector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ def to_html_tbody(threshold=30)
end

def to_s
"#<#{self.class}#{': ' + @name if @name}(#{size})#{':category' if category?}>"
"#<#{self.class}#{': ' + @name.to_s if @name}(#{size})#{':category' if category?}>"
end

# Create a summary of the Vector
Expand Down
5 changes: 5 additions & 0 deletions spec/dataframe_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3866,6 +3866,11 @@ def create_test(*args, &_proc)
@data_frame.name = "Test"
expect(@data_frame.to_s).to eq "#<Daru::DataFrame: Test(5x3)>"
end

it 'produces a class, name, size description when the name is a symbol' do
@data_frame.name = :Test
expect(@data_frame.to_s).to eq "#<Daru::DataFrame: Test(5x3)>"
end
end

context '#to_json' do
Expand Down
5 changes: 5 additions & 0 deletions spec/vector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,11 @@
@v.name = "Test"
expect(@v.to_s).to eq("#<Daru::Vector: Test(2)>")
end

it 'produces a class, name, size description when the name is a symbol' do
@v.name = :Test
expect(@v.to_s).to eq("#<Daru::Vector: Test(2)>")
end
end

context "#uniq" do
Expand Down

0 comments on commit 843a2ef

Please sign in to comment.