Skip to content

Commit 843a2ef

Browse files
baarkerloungerv0dro
authored andcommitted
Fix to_s when name is a symbol #381 (#383)
* Fix to_s when name is a symbol * Add spec for breaking case
1 parent a46949f commit 843a2ef

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

lib/daru/dataframe.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1902,7 +1902,7 @@ def to_html_tbody(threshold=30)
19021902
end
19031903

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

19081908
# Method for updating the metadata (i.e. missing value positions) of the

lib/daru/vector.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ def to_html_tbody(threshold=30)
938938
end
939939

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

944944
# Create a summary of the Vector

spec/dataframe_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -3866,6 +3866,11 @@ def create_test(*args, &_proc)
38663866
@data_frame.name = "Test"
38673867
expect(@data_frame.to_s).to eq "#<Daru::DataFrame: Test(5x3)>"
38683868
end
3869+
3870+
it 'produces a class, name, size description when the name is a symbol' do
3871+
@data_frame.name = :Test
3872+
expect(@data_frame.to_s).to eq "#<Daru::DataFrame: Test(5x3)>"
3873+
end
38693874
end
38703875

38713876
context '#to_json' do

spec/vector_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,11 @@
10281028
@v.name = "Test"
10291029
expect(@v.to_s).to eq("#<Daru::Vector: Test(2)>")
10301030
end
1031+
1032+
it 'produces a class, name, size description when the name is a symbol' do
1033+
@v.name = :Test
1034+
expect(@v.to_s).to eq("#<Daru::Vector: Test(2)>")
1035+
end
10311036
end
10321037

10331038
context "#uniq" do

0 commit comments

Comments
 (0)