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: ruff rule F821 (undefined name) #54

Merged
merged 3 commits into from
May 30, 2023
Merged

fix: ruff rule F821 (undefined name) #54

merged 3 commits into from
May 30, 2023

Conversation

thatlittleboy
Copy link
Collaborator

@thatlittleboy thatlittleboy commented May 20, 2023

Related to Issue #21, and is a continuation of PR #25 when ruff was initially introduced to the project.

Dependencies: PR #53 (deprecating MimicExplainer) must be merged in first, because that's one of the main offenders of F821. ✅


Changes

The changes are quite major considering it involves mostly dead / unreachable code. Requesting a thorough review, but any review (even partial!) would be appreciated. I'll leave review comments in the relevant places later on to make code review a little easier for you guys, but here's the tl;dr:

  1. Explanation.hstack method was using a non-existent variable "axis" (probably copied from the other helper methods like sum). The implementation as it is didn't make any sense, so I modified it to what I think made the most sense, which is to hstack the inner arrays and return a new Explanation object.DONE in PR fix: Explanation hstack undefined name error #86
  2. beeswarm plot function was using non-existent variables like title, sort, plot_type which came from the summary_legacy() function, within an unreachable code block meant for SHAP interaction values. I've commented out the block for now to prevent ruff from complaining, but we should look into re-implementing this functionality. -> Issue Reimplement SHAP interaction values in beeswarm #56.
  3. I revampedviolin plot code quite a bit. The original violin was essentially a copy-paste from the summary_legacy() function, so there's a lot of redundant code (including a call to a "non-existent" summary() function) checking for "bar" or "dot" plot types. These have all been removed. Violin plots don't support multioutputs (only bar plots support this), so that section has been removed as well.DONE in PR fix: violin plots tests #87
    • I'll note that the code for violin is still in the "legacy" style. For e.g., it still accepts shap_values as a numpy array. Whereas beeswarm only takes in Explanation objects, which I think we should align to that convention. -> Issue Refactor _violin plot code and add examples #55.
  4. The plot tests for violin in test_violin.py and test_summary.py were revamped. In particular, the original test was just an empty plot...DONE in PR fix: violin plots tests #87

shap/plots/_beeswarm.py Show resolved Hide resolved
shap/plots/_beeswarm.py Outdated Show resolved Hide resolved
shap/plots/_violin.py Outdated Show resolved Hide resolved
shap/plots/_violin.py Outdated Show resolved Hide resolved
shap/plots/_violin.py Outdated Show resolved Hide resolved
@thatlittleboy thatlittleboy added the waiting for test suite PRs on hold until the main test suite passes label May 20, 2023
@thatlittleboy thatlittleboy force-pushed the ruff-F821 branch 3 times, most recently from a0dc862 to c28fe5b Compare May 26, 2023 01:18
@codecov
Copy link

codecov bot commented May 26, 2023

Codecov Report

Merging #54 (bc4ee55) into master (fc8fb88) will increase coverage by 0.19%.
The diff coverage is 75.00%.

❗ Current head bc4ee55 differs from pull request most recent head d396f1c. Consider uploading reports for the commit d396f1c to get more accurate results

@@            Coverage Diff             @@
##           master      #54      +/-   ##
==========================================
+ Coverage   53.39%   53.58%   +0.19%     
==========================================
  Files          90       90              
  Lines       13028    12982      -46     
==========================================
+ Hits         6956     6957       +1     
+ Misses       6072     6025      -47     
Impacted Files Coverage Δ
shap/plots/_beeswarm.py 53.75% <50.00%> (+4.56%) ⬆️
shap/plots/_utils.py 13.24% <50.00%> (+0.57%) ⬆️
shap/plots/_violin.py 75.86% <80.00%> (ø)
shap/_explanation.py 55.66% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@thatlittleboy thatlittleboy marked this pull request as ready for review May 26, 2023 03:09
@thatlittleboy thatlittleboy removed the waiting for test suite PRs on hold until the main test suite passes label May 26, 2023
shap/_explanation.py Outdated Show resolved Hide resolved
@connortann
Copy link
Collaborator

This is a major PR, great work! Would it be possible to break it into a few smaller PRs, to make it a bit easier to review?

@thatlittleboy
Copy link
Collaborator Author

thatlittleboy commented May 26, 2023

This is a major PR, great work! Would it be possible to break it into a few smaller PRs, to make it a bit easier to review?

okay (although, the changes are already split by the commits, so it'll be largely equivalent to reviewing the commits one-by-one)

EDIT: I split out the Explanation and violin changes to their own PRs. The rest are small enough to remain here, I think. @connortann

@thatlittleboy thatlittleboy marked this pull request as draft May 26, 2023 11:20
And also temporarily remove the SHAP interaction beeswarm plot code
(it's not runnable at the moment, because we ensured that the ndim of
SHAP values was 2 above, so it can never be 3 to trigger the interaction
beeswarm plot here).

The removal of code here is mostly just to appease ruff.
Will create a separate issue for this to re-introduce SHAP interaction
values plotting again later on. Maybe it should be implemented as a
separate function.
@thatlittleboy thatlittleboy marked this pull request as ready for review May 29, 2023 14:00
@thatlittleboy
Copy link
Collaborator Author

I'll address the codecov issues in a separate PR. Please disregard coverage and review/merge the rest of the changes first. Thanks!

Copy link
Owner

@dsgibbons dsgibbons left a comment

Choose a reason for hiding this comment

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

I'll approve as is for now and open a new PR to address convert_color, as this falls out of scope.

shap/plots/_utils.py Show resolved Hide resolved
@dsgibbons dsgibbons merged commit 14c76da into master May 30, 2023
@thatlittleboy thatlittleboy deleted the ruff-F821 branch May 31, 2023 00:10
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.

3 participants