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

Fix _is_single from Phrases for case when corpus is numpy array of tokens #1987

Merged
merged 3 commits into from
Mar 20, 2018

Conversation

rmalouf
Copy link
Contributor

@rmalouf rmalouf commented Mar 20, 2018

Transforming a corpus using Phraser[] fails with:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

if the corpus is a numpy array, a pandas Series, or anything else that defaults to element-wise comparison.

The problem is this check here:

if temp_iter == obj:

A simple fix is replacing == with is

@@ -118,7 +118,7 @@ def _is_single(obj):
if isinstance(peek, string_types):
# It's a document, return the iterator
return True, obj_iter
if temp_iter == obj:
if temp_iter is obj:
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to add a clear test for the case when this doesn't work correctly without this fix (and now it works).
Also, return mode of file please (755 -> 644).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@menshikh-iv menshikh-iv changed the title fix _is_single element-wise comparison error Fix _is_single from Phrases for case when corpus is numpy array of tokens Mar 20, 2018
@menshikh-iv
Copy link
Contributor

Good catch @rmalouf, congratz with the first contribution 🥇

@menshikh-iv menshikh-iv merged commit 7652825 into piskvorky:develop Mar 20, 2018
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