Closed Shekharrajak closed 7 years ago
Now in dataframe
we can see Index name. I have added the testcases for it.
Add documentation to all modified user methods specifying that a name attribute can be used with index. Rest looks good (apart from that specs comment).
I think now this PR is good to go.
@zverok , I have added testcases when index name is shorter/longer than index levels in new commit.
These examples shows the MultiIndex behavior if the index name is shorter/longer than index levels :
irb(main):002:0* mi =Daru::MultiIndex.new(
irb(main):003:1* levels: [[:a,:b,:c], [:one, :two]],
irb(main):004:1* labels: [[0,0,1,1,2,2], [0,1,0,1,0,1]], name: ['s1', 's2'])
=> #<Daru::MultiIndex(6x2)>
s1 s2
a one
two
b one
two
c one
two
irb(main):005:0>
irb(main):006:0* mi =Daru::MultiIndex.new(
irb(main):007:1* levels: [[:a,:b,:c], [:one, :two]],
irb(main):008:1* labels: [[0,0,1,1,2,2], [0,1,0,1,0,1]], name: ['s1'])
SizeError: names and levels should be of same size. size of the name array is 1 and size of the MultiIndex levels and labels is 2.
If you don't want to set name for particular level(say level `i`) then put empty string on index `i` of the `name` Array.
irb(main):009:0>
irb(main):010:0* mi =Daru::MultiIndex.new(
irb(main):011:1* levels: [[:a,:b,:c], [:one, :two]],
irb(main):012:1* labels: [[0,0,1,1,2,2], [0,1,0,1,0,1]], name: ['s1', 's2', 's3'])
SizeError: names and levels should be of same size. size of the name array is 3 and size of the MultiIndex levels and labels is 2.
irb(main):013:0> mi
=> #<Daru::MultiIndex(6x2)>
s1 s2
a one
two
b one
two
c one
two
irb(main):014:0> mi.name = ['k1']
SizeError: names and levels should be of same size. size of the name array is 1 and size of the MultiIndex levels and labels is 2.
If you don't want to set name for particular level(say level `i`) then put empty string on index `i` of the `name` Array.
irb(main):015:0> mi.name = ['k1', 'k2']
=> ["k1", "k2"]
irb(main):016:0> mi
=> #<Daru::MultiIndex(6x2)>
k1 k2
a one
two
b one
two
c one
two
irb(main):017:0> mi.name = ['k1', 'k2', 'k3']
SizeError: names and levels should be of same size. size of the name array is 3 and size of the MultiIndex levels and labels is 2.
irb(main):018:0> mi.name = ['k1', '']
=> ["k1", ""]
irb(main):019:0> mi
=> #<Daru::MultiIndex(6x2)>
k1
a one
two
b one
two
c one
two
irb(main):020:0> mi.name = ['', 'k2']
=> ["", "k2"]
irb(main):021:0> mi
=> #<Daru::MultiIndex(6x2)>
k2
a one
two
b one
two
c one
two
Travis is still showing random error .
@Shekharrajak - Travis isn't showing random error (s). Apparently, rubocop released version 0.48.1 which has better offense detection than 0.47.0 - and hence, the build is failing on master. This issue has been fixed on PR #329 - so you don't have to fix the rubocop offenses again. Build will be successful on master, once that PR has been merged. :smile:
Thanks @athityakumar .
Checks passed! I hope, now PR is ready for review.
Thanks for your work! :tada:
Fixes https://github.com/SciRuby/daru/issues/223
Example :