Skip to content

Conversation

@karpet
Copy link

@karpet karpet commented Oct 18, 2017

This fixes an Argument exception

ArgumentError: comparison of Array with Array failed
~/.rvm/gems/ruby-2.4.2/gems/fuzzy_tools-1.0.0/lib/fuzzy_tools/index.rb:25:in `sort_by'
~/.rvm/gems/ruby-2.4.2/gems/fuzzy_tools-1.0.0/lib/fuzzy_tools/index.rb:25:in `all_with_scores'
~/.rvm/gems/ruby-2.4.2/gems/fuzzy_tools-1.0.0/lib/fuzzy_tools/core_ext/enumerable.rb:16:in `fuzzy_find_all_with_scores'

@brianhempel
Copy link
Owner

I did a once-over this code again (wow, people are using this library? Woo!) and I can't see where that NaN could be coming from.

Are you using a custom weight function? Do you have an example of a case that fails?

@karpet
Copy link
Author

karpet commented Oct 19, 2017

No custom code. I was able to reproduce it with this code:

2.4.2 :001 > require 'fuzzy_tools'
 => true
2.4.2 :002 > str = 'Ward 2'
 => "Ward 2"
2.4.2 :003 > pool = ['Township 1 Precinct 2', 'Township 2']
 => ["Township 1 Precinct 2", "Township 2"]
2.4.2 :004 > pool.fuzzy_find_all_with_scores(str)
query="Ward 2"
unsorted:[["Township 1 Precinct 2", 0.0], ["Township 2", NaN]]
ArgumentError: comparison of Array with Array failed
	from /Users/karpet/.rvm/gems/ruby-2.4.2/gems/fuzzy_tools-1.0.0/lib/fuzzy_tools/index.rb:26:in `sort_by'
	from /Users/karpet/.rvm/gems/ruby-2.4.2/gems/fuzzy_tools-1.0.0/lib/fuzzy_tools/index.rb:26:in `all_with_scores'
	from /Users/karpet/.rvm/gems/ruby-2.4.2/gems/fuzzy_tools-1.0.0/lib/fuzzy_tools/core_ext/enumerable.rb:16:in `fuzzy_find_all_with_scores'
	from (irb):4
	from /Users/karpet/.rvm/rubies/ruby-2.4.2/bin/irb:11:in `<main>'

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.

2 participants