Sha256: c8655ea918a0661d7ad7772cbb4ef8ed29d27d8280a2434bc138c9e4148df162

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

require 'daru_lite/extensions/which_dsl'

describe "which DSL" do
  before do
    @df = DaruLite::DataFrame.new({
      number: [1,2,3,4,5,6,Float::NAN],
      sym: [:one, :two, :three, :four, :five, :six, :seven],
      names: ['sameer', 'john', 'james', 'omisha', 'priyanka', 'shravan',nil]
    })
  end

  it "accepts simple single eq statement" do
    answer = DaruLite::DataFrame.new({
      number: [4],
      sym: [:four],
      names: ['omisha']
      }, index: DaruLite::Index.new([3])
    )
    expect( @df.which{ `number` == 4 } ).to eq(answer)
  end

  it "accepts somewhat complex comparison operator chaining" do
    answer = DaruLite::DataFrame.new({
      number: [3,4],
      sym: [:three, :four],
      names: ['james', 'omisha']
    }, index: DaruLite::Index.new([2,3]))
    expect(
      @df.which{ (`names` == 'james') | (`sym` == :four) }
      ).to eq(answer)
  end

  it "accepts vector methods" do
    # expect( @df.which{ `number` == `number`.only_valid.max } ).to eq(@df.row_at(5)) # row_at(5) return a Vector object!?
    expect( @df.which{ `number` <= `number`.only_valid.max } ).to eq(@df.row_at(0..5))
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
daru_lite-0.1.3 spec/extensions/which_dsl_spec.rb
daru_lite-0.1.2 spec/extensions/which_dsl_spec.rb
daru_lite-0.1.1 spec/extensions/which_dsl_spec.rb
daru_lite-0.1 spec/extensions/which_dsl_spec.rb