Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support to missing data for where clause #302

Merged
merged 5 commits into from
Feb 9, 2017

Conversation

athityakumar
Copy link
Member

@athityakumar athityakumar commented Feb 6, 2017

Fixes issue #246. Sample output for the building pass is shown below.

2.3.1 :002 > v= Daru::Vector.new([1,2,3,Float::NAN, nil])
 => #<Daru::Vector(5)>
   0   1
   1   2
   2   3
   3 NaN
   4 nil 
2.3.1 :003 > v.where(v.lt(4))

 => #<Daru::Vector(3)>
   0   1
   1   2
   2   3 
2.3.1 :004 > v.where(v.lt(2))

 => #<Daru::Vector(1)>
   0   1 
2.3.1 :005 > v.where(v.lt(3))

 => #<Daru::Vector(2)>
   0   1
   1   2 
2.3.1 :006 > v.where(v.gt(1))

 => #<Daru::Vector(2)>
   1   2
   2   3 

Ping @v0dro @zverok @lokeshh - Please review this PR when you're free. 😄

@athityakumar athityakumar changed the title Adds support to missing data for where clause - nil? check Adds support to missing data for where clause Feb 6, 2017
Changed the C offsenses of travis CI

Fixes Travis CI error :  Favor unless over if
Copy link
Collaborator

@zverok zverok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests, please?

(And, side note: I'd advise you not to rush fixing each and every issue in a single day. Better to work on something relatively large, to understand our code quality expectations and processes. We greatly appreciate your effort, though!)

@athityakumar
Copy link
Member Author

Tests, as in using Travis CI or test-unit gem?

@zverok
Copy link
Collaborator

zverok commented Feb 6, 2017

@athityakumar I've meant specs -- there are ton of them & you can run them locally by just rspec or rspec path/to/your/spec.rb

@v0dro
Copy link
Member

v0dro commented Feb 7, 2017

@athityakumar I suggest you first go through the CONTRIBUTING file and understand our processes properly before submitting PRs. We're all volunteers and it saves our time if you abide by some formal processes.

@v0dro
Copy link
Member

v0dro commented Feb 7, 2017

Also, submitting a PR without tests is not acceptable. Especially if you want to apply for GSOC.

@@ -39,7 +39,7 @@ def inspect

class << self
def apply_scalar_operator operator, data, other
BoolArray.new data.map { |d| !!d.send(operator, other) }
BoolArray.new data.map { |d| !!d.send(operator, other) unless d.nil? }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing data is not just nil. What if the Vector contains strings combined with a Float::NaN? This will fail in that case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@v0dro Float::NaN I think are only used in numerical domain. I don't think they ever occur with strings or any other object except numbers.

@athityakumar
Copy link
Member Author

athityakumar commented Feb 7, 2017

@v0dro : Thanks for mentioning about the CONTRIBUTING.md file - I just read through it. I'll add the tests in a day, after including the other missing data types and let you know for reviewing the PR again.

@athityakumar
Copy link
Member Author

@v0dro @zverok : The PR is ready for another review.

Updates -

(1) Thanks for the rspec and rubocop references. They really made testing the changes simpler.
(2) Support added for other missing data types like Float:NAN and Float:NAN in string.
(3) Tests have been written for Daru::Vector#where and Daru::DataFrame#where.

Any changes required?

names: ['sameer', 'john', 'james', 'omisha', 'priyanka', 'shravan']
number: [1,2,3,4,5,6,nil],
sym: [:one, :two, :three, :four, :five, :six, :seven],
names: ['sameer', 'john', 'james', 'omisha', 'priyanka', 'shravan', Float::NAN.to_s]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why Float::NAN.to_s should be considered as a missing value?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was meant to be Float::NAN missing type as mentioned here. I will change that in the next commit, along with other changes. 😄

names: [Float::NAN.to_s]
}, index: Daru::Index.new([6])
)
expect(@df.where(@df[:sym].eq(:seven))).to eq(answer)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an old saying "Don't believe test you've never seen failing". It means: you should first make sure this test is failing without your patch, then apply the patch, then check test is green.
Hint: it doesn't check anything (on current daru master it will work).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, my bad. Will it be fine if I include the test case provided by @v0dro at issue #246 ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, think so.

@athityakumar
Copy link
Member Author

athityakumar commented Feb 8, 2017

@zverok : I've added the specific test that would have failed on the current master branch version of daru. As suggested, I've also added my test variables in letformat - however, it does seem a bit different / inconsistent with the rest of the tests in the spec/core/query_spec.rb file, as they don't use let format.

@zverok
Copy link
Collaborator

zverok commented Feb 9, 2017

however, it does seem a bit different / inconsistent with the rest of the tests in the spec/core/query_spec.rb file, as they don't use let format.

Yes, part of the specs are just old and written without much attention. We want to have them rewritten in modern style with time, yet it was not done yet.

let(:dv1) { Daru::Vector.new([1,11,32,Float::NAN,nil]) }
let(:dv2) { Daru::Vector.new([1,11]) }
it "handles empty data" do
expect(dv1.where(dv1.lt(14))).to eq(dv2)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure you need to create separate dv, expect(dv1.where(dv1.lt(14))).to eq(Daru::Vector.new([1,11])) should be enough.

@athityakumar
Copy link
Member Author

athityakumar commented Feb 9, 2017

@v0dro @zverok : Made the required changes in tests. 😄

@v0dro v0dro merged commit 8a4bb1c into SciRuby:master Feb 9, 2017
@athityakumar athityakumar mentioned this pull request Feb 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants