SciRuby / daru

Data Analysis in RUby
BSD 2-Clause "Simplified" License
1.04k stars 139 forks source link

defining sort for Index and sort_by_index for vector #315

Closed Shekharrajak closed 7 years ago

Shekharrajak commented 7 years ago

Fixes https://github.com/SciRuby/daru/issues/159

irb(main):007:0> dv = Daru::Vector.new [11, Float::NAN, nil], index: [23, 22, 21]
=> #<Daru::Vector(3)>
  23  11
  22 NaN
  21 nil
irb(main):008:0> dv.sort_by_index()
=> #<Daru::Vector(3)>
  21 nil
  22 NaN
  23  11
irb(main):009:0> dv = Daru::Vector.new [11, 12, 13], index: [23, 22, 21]
=> #<Daru::Vector(3)>
  23  11
  22  12
  21  13
irb(main):010:0> dv.sort_by_index()
=> #<Daru::Vector(3)>
  21  13
  22  12
  23  11
irb(main):011:0> dv.sort_by_index(ascending: false)
=> #<Daru::Vector(3)>
  23  11
  22  12
  21  13
Shekharrajak commented 7 years ago

I didn't understand why this case is failing . Let me know if someone find the mistake in testcase.

Shekharrajak commented 7 years ago

@zverok @v0dro , I think now this PR is good to go. Please review.

Shekharrajak commented 7 years ago

@zverok , I think now this PR is good to go.

Shekharrajak commented 7 years ago

@v0dro , have a look once.