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

add brackets to the shape argument of reshape when calling as np.resh… #2799

Merged
merged 2 commits into from Dec 4, 2023

Conversation

SomeUserName1
Copy link
Contributor

…ape(a, (x,y)).

When calling np.reshape(a, shape), the shape argument needs to be in brackets, otherwise the second dimension of the shape argument is interpreted as thrid argument which is actually order (i.e. specifying how the array is indexed).

File "/opt/miniconda3/envs/xai/lib/python3.10/site-packages/shap/plots/_scatter.py", line 559, in dependence_legacy
    shap_values = np.reshape(shap_values, len(shap_values), 1)         # here we are missing brackets
  File "<__array_function__ internals>", line 180, in reshape
  File "/opt/miniconda3/envs/xai/lib/python3.10/site-packages/numpy/core/fromnumeric.py", line 298, in reshape
    return _wrapfunc(a, 'reshape', newshape, order=order)                # Causing newshape to be a single int and the second dimension gets interpreted as order
  File "/opt/miniconda3/envs/xai/lib/python3.10/site-packages/numpy/core/fromnumeric.py", line 54, in _wrapfunc
    return _wrapit(obj, method, *args, **kwds)
  File "/opt/miniconda3/envs/xai/lib/python3.10/site-packages/numpy/core/fromnumeric.py", line 43, in _wrapit
    result = getattr(asarray(obj), method)(*args, **kwds)
TypeError: order must be str, not int                                                 # Causing this error

The fix is to add brackets:
shap_values = np.reshape(shap_values, (len(shap_values), 1))

@connortann connortann added the bug Indicates an unexpected problem or unintended behaviour label Dec 4, 2023
Copy link
Collaborator

@connortann connortann left a comment

Choose a reason for hiding this comment

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

LGTM!

@connortann connortann merged commit d7f414e into shap:master Dec 4, 2023
13 checks passed
@SomeUserName1 SomeUserName1 deleted the fix_scatter_reshape branch December 13, 2023 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behaviour
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants