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

enforce ruff checks on Python code in notebooks (fixes #333) #370

Merged
merged 4 commits into from
Apr 25, 2024

Conversation

jameslamb
Copy link
Member

@jameslamb jameslamb commented Apr 22, 2024

Fixes #333.

  • adds enforcement of ruff checks on Python code in notebooks
  • upgrades ruff to its latest version (v0.4.1)
  • fixes all of the remaining warnings issued by ruff`
source/examples/rapids-1brc-single-node/notebook.ipynb:cell 7:1:1: I001 [*] Import block is un-sorted or un-formatted
source/examples/rapids-1brc-single-node/notebook.ipynb:cell 12:13:121: E501 Line too long (129 > 120)
source/examples/rapids-autoscaling-multi-tenant-kubernetes/notebook.ipynb:cell 43:2:1: E402 Module level import not at top of cell
source/examples/rapids-autoscaling-multi-tenant-kubernetes/notebook.ipynb:cell 43:3:1: E402 Module level import not at top of cell
source/examples/rapids-autoscaling-multi-tenant-kubernetes/notebook.ipynb:cell 51:6:1: I001 [*] Import block is un-sorted or un-formatted
source/examples/rapids-autoscaling-multi-tenant-kubernetes/notebook.ipynb:cell 51:7:42: F401 [*] `dask.distributed.wait` imported but unused
source/examples/rapids-ec2-mnmg/notebook.ipynb:cell 4:3:17: F821 Undefined name `cluster`
source/examples/rapids-ec2-mnmg/notebook.ipynb:cell 7:1:1: I001 [*] Import block is un-sorted or un-formatted
source/examples/rapids-ec2-mnmg/notebook.ipynb:cell 7:1:8: F401 [*] `math` imported but unused
source/examples/rapids-ec2-mnmg/notebook.ipynb:cell 7:2:22: F401 [*] `datetime.datetime` imported but unused
source/examples/rapids-ec2-mnmg/notebook.ipynb:cell 7:4:8: F401 [*] `cudf` imported but unused
source/examples/rapids-ec2-mnmg/notebook.ipynb:cell 7:5:8: F401 [*] `dask` imported but unused
source/examples/rapids-ec2-mnmg/notebook.ipynb:cell 7:13:22: F401 [*] `dateutil.parser` imported but unused
source/examples/rapids-ec2-mnmg/notebook.ipynb:cell 7:14:1: E401 [*] Multiple imports on one line
source/examples/rapids-ec2-mnmg/notebook.ipynb:cell 7:14:8: F401 [*] `configparser` imported but unused
source/examples/rapids-ec2-mnmg/notebook.ipynb:cell 7:14:22: F401 [*] `os` imported but unused
source/examples/rapids-ec2-mnmg/notebook.ipynb:cell 7:14:26: F401 [*] `contextlib` imported but unused
source/examples/rapids-ec2-mnmg/notebook.ipynb:cell 27:3:1: F821 Undefined name `cluster`
source/examples/rapids-sagemaker-higgs/notebook.ipynb:cell 3:1:1: I001 [*] Import block is un-sorted or un-formatted
source/examples/rapids-sagemaker-higgs/notebook.ipynb:cell 31:1:1: I001 [*] Import block is un-sorted or un-formatted
source/examples/time-series-forecasting-with-hpo/notebook.ipynb:cell 23:1:1: I001 [*] Import block is un-sorted or un-formatted
source/examples/time-series-forecasting-with-hpo/notebook.ipynb:cell 23:13:12: UP031 Use format specifiers instead of percent format
source/examples/time-series-forecasting-with-hpo/notebook.ipynb:cell 90:11:13: E741 Ambiguous variable name: `l`
source/examples/time-series-forecasting-with-hpo/notebook.ipynb:cell 109:1:1: I001 [*] Import block is un-sorted or un-formatted
source/examples/time-series-forecasting-with-hpo/notebook.ipynb:cell 120:46:5: F841 Local variable `t` is assigned to but never used
source/examples/time-series-forecasting-with-hpo/notebook.ipynb:cell 143:4:9: F841 Local variable `product_weights` is assigned to but never used
source/examples/xgboost-azure-mnmg-daskcloudprovider/notebook.ipynb:cell 7:1:1: I001 [*] Import block is un-sorted or un-formatted
source/examples/xgboost-azure-mnmg-daskcloudprovider/notebook.ipynb:cell 7:1:44: F401 [*] `dask.distributed.get_worker` imported but unused
source/examples/xgboost-azure-mnmg-daskcloudprovider/notebook.ipynb:cell 7:5:39: F401 [*] `cuml.dask.common.utils` imported but unused
source/examples/xgboost-azure-mnmg-daskcloudprovider/notebook.ipynb:cell 7:7:18: F401 [*] `cuml.ForestInference` imported but unused
source/examples/xgboost-azure-mnmg-daskcloudprovider/notebook.ipynb:cell 7:8:8: F401 [*] `cudf` imported but unused
source/examples/xgboost-azure-mnmg-daskcloudprovider/notebook.ipynb:cell 7:10:22: F401 [*] `datetime.datetime` imported but unused
source/examples/xgboost-azure-mnmg-daskcloudprovider/notebook.ipynb:cell 7:11:22: F401 [*] `dateutil.parser` imported but unused
source/examples/xgboost-azure-mnmg-daskcloudprovider/notebook.ipynb:cell 23:25:121: E501 Line too long (133 > 120)
source/examples/xgboost-azure-mnmg-daskcloudprovider/notebook.ipynb:cell 49:1:1: I001 [*] Import block is un-sorted or un-formatted
source/examples/xgboost-azure-mnmg-daskcloudprovider/notebook.ipynb:cell 49:37:13: B007 Loop control variable `d_1` not used within loop body
source/examples/xgboost-azure-mnmg-daskcloudprovider/notebook.ipynb:cell 49:37:18: B007 Loop control variable `m_1` not used within loop body
source/examples/xgboost-azure-mnmg-daskcloudprovider/notebook.ipynb:cell 49:37:23: B007 Loop control variable `y_1` not used within loop body
source/examples/xgboost-azure-mnmg-daskcloudprovider/notebook.ipynb:cell 78:25:23: F401 [*] `xgboost` imported but unused
source/examples/xgboost-azure-mnmg-daskcloudprovider/notebook.ipynb:cell 78:26:22: F811 [*] Redefinition of unused `ForestInference` from cell 7, line 7

Notes for Reviewers

I thought the number of remaining issues was small enough that it was time to put up a "fix everything else" PR to close this out. But if this is too large to review let me know, I'd be happy to split it up.

How I tested this

I did not run any of these notebooks.

For any places where ruff said an import was "unused", I searched through that notebook to check if it was referenced in commented-out code or in markdown blocks.

@jameslamb jameslamb added improvement Improves an existing functionality non-breaking Introduces a non-breaking change labels Apr 22, 2024
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@jameslamb jameslamb marked this pull request as ready for review April 22, 2024 15:37
@jameslamb jameslamb changed the title WIP: enforce ruff checks on Python code in notebooks (fixes #333) enforce ruff checks on Python code in notebooks (fixes #333) Apr 22, 2024
Copy link
Member

@jacobtomlinson jacobtomlinson left a comment

Choose a reason for hiding this comment

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

Thanks @jameslamb. See responses to your comments.

@jacobtomlinson jacobtomlinson merged commit 5d13f7f into rapidsai:main Apr 25, 2024
3 checks passed
@jameslamb jameslamb deleted the ci/add-notebook-linting branch April 25, 2024 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improves an existing functionality non-breaking Introduces a non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ci] use nbqa or ruff to auto-format and lint notebooks?
2 participants