-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
[MRG + 1] Fix element-wise comparison for numpy #8011
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
Conversation
@lesteve: I followed your instructions which gave me the below error in this particular line: Error:
On a side note, what do you mean when you say install numpy from master ? |
Hmmm that means that somewhere the string 'variance_weighted' is turned into an array ... so the string_types clause is skipped. You will need to either:
My preference is for 1.
That means installing the numpy development version because that is what the original issue was about. You can still work on this issue without it but the only way to make sure the original issue is fixed is through Travis. This can be a bit cumbersome and frustrating because the feedback loop is a lot longer that testing things locally. |
@@ -90,7 +90,10 @@ def _check_reg_targets(y_true, y_pred, multioutput): | |||
n_outputs = y_true.shape[1] | |||
multioutput_options = (None, 'raw_values', 'uniform_average', | |||
'variance_weighted') | |||
if multioutput not in multioutput_options: | |||
if isinstance(multioutput, string_types) and multioutput not in multioutput_options: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When any value among raw_values
, uniform_average
or variance_weighted
is passed, this condition is not met since it checks for invalid multioutput_option
. We don't have any check for multioutput
being a string type and a valid multioutput_option
. That check needs to be added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will refine the if else to make sure we account for the correct multioutput check there.
@@ -90,7 +90,10 @@ def _check_reg_targets(y_true, y_pred, multioutput): | |||
n_outputs = y_true.shape[1] | |||
multioutput_options = (None, 'raw_values', 'uniform_average', | |||
'variance_weighted') | |||
if multioutput not in multioutput_options: | |||
if isinstance(multioutput, string_types) and multioutput not in multioutput_options: | |||
raise ValueError("Invalid multioutput value") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel it's better to use Invalid multioutput option
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. If that's what you prefer.
However, it does seem natural that |
@lesteve I think the string_types clause is not skipped but within the |
Sure @aashil. From what I see, you need to add another check if elif multioutput is not None: To: elif multioutput is not None and multioutput not in multioutput_options: That should be all. |
@dalmia I believe you mean |
@aashil Sorry I made a small mistake. Also, I don't think I conveyed properly what I intended to say. Let me elaborate what I intend to say. multioutput_options = (None, 'raw_values', 'uniform_average',
'variance_weighted')
# If it is a string, but not a valid option, raise an error
if isinstance(multioutput, string_types) and multioutput not in multioutput_options:
raise ValueError("Invalid multioutput option")
# If it is not a string then check for the validity of the array
elif multioutput is not None and not isinstance(multioutput, string_types):
multioutput = check_array(multioutput, ensure_2d=False)
if n_outputs == 1: |
@dalmia Ahh, that makes it so clear. Thank you. |
1e8d7c5
to
019f892
Compare
* Refactored the if clause and add proper check for valid strings. * Fix PEP8 errors.
019f892
to
7ef3323
Compare
Sure, happy to help :) |
LGTM |
Tested locally. LGTM |
OK, merging then, thanks a lot @aashil! |
Was causing "ValueError: The truth value of an array with more than one element is ambiguous"
Was causing "ValueError: The truth value of an array with more than one element is ambiguous"
Was causing "ValueError: The truth value of an array with more than one element is ambiguous"
Was causing "ValueError: The truth value of an array with more than one element is ambiguous"
Was causing "ValueError: The truth value of an array with more than one element is ambiguous"
Reference Issue
Working on #7994
What does this implement/fix? Explain your changes.
Any other comments?
Fix the element-wise comparision issue with numpy.