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

(chore): Update to Ruff 0.9 and add EM lints #1825

Merged
merged 4 commits into from
Jan 16, 2025
Merged

Conversation

flying-sheep
Copy link
Member

@flying-sheep flying-sheep commented Jan 13, 2025

Since Ruff 0.9 touches a bunch of Exception instantiations, I thought adding the EM lints now is a good time. See #1241

The coverage issues are expected as we don’t test some just-in-case exception raisings. So a PR touching many spots that involve instantiating exceptions will have low coverage.

@flying-sheep flying-sheep mentioned this pull request Jan 13, 2025
17 tasks
Copy link

codecov bot commented Jan 13, 2025

Codecov Report

Attention: Patch coverage is 37.96992% with 165 lines in your changes missing coverage. Please review.

Project coverage is 83.64%. Comparing base (cceaa75) to head (bd0faf0).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/anndata/_core/anndata.py 32.30% 44 Missing ⚠️
src/anndata/experimental/merge.py 16.66% 20 Missing ⚠️
src/anndata/_core/merge.py 33.33% 16 Missing ⚠️
src/anndata/_core/sparse_dataset.py 50.00% 12 Missing ⚠️
src/anndata/tests/helpers.py 0.00% 11 Missing ⚠️
...anndata/experimental/multi_files/_anncollection.py 0.00% 8 Missing ⚠️
src/anndata/utils.py 42.85% 8 Missing ⚠️
src/anndata/_core/file_backing.py 0.00% 6 Missing ⚠️
src/anndata/_core/index.py 66.66% 6 Missing ⚠️
src/anndata/_io/read.py 40.00% 6 Missing ⚠️
... and 10 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1825      +/-   ##
==========================================
- Coverage   87.09%   83.64%   -3.46%     
==========================================
  Files          40       40              
  Lines        6138     6267     +129     
==========================================
- Hits         5346     5242     -104     
- Misses        792     1025     +233     
Files with missing lines Coverage Δ
src/anndata/_core/aligned_mapping.py 93.44% <100.00%> (+0.02%) ⬆️
src/anndata/_io/specs/lazy_methods.py 97.80% <100.00%> (+0.04%) ⬆️
src/anndata/_io/write.py 77.77% <100.00%> (+0.24%) ⬆️
src/anndata/_settings.py 94.11% <100.00%> (ø)
src/anndata/io.py 100.00% <ø> (ø)
src/anndata/logging.py 50.00% <ø> (ø)
src/anndata/__init__.py 90.62% <0.00%> (-2.93%) ⬇️
src/anndata/_core/aligned_df.py 95.65% <0.00%> (-2.13%) ⬇️
src/anndata/_core/views.py 85.02% <50.00%> (-6.09%) ⬇️
src/anndata/_io/h5ad.py 92.68% <80.00%> (-0.32%) ⬇️
... and 16 more

@flying-sheep flying-sheep changed the title Update to Ruff 0.9 and add EM lints (chore): Update to Ruff 0.9 and add EM lints Jan 13, 2025
Copy link
Member Author

@flying-sheep flying-sheep left a comment

Choose a reason for hiding this comment

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

All code changes in this PR are mechanical, except for the obvious (add EM to ruff config, bump Ruff version) and the ones noted below:

hooks:
- id: ruff
types_or: [python, pyi, jupyter]
Copy link
Member Author

@flying-sheep flying-sheep Jan 13, 2025

Choose a reason for hiding this comment

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

This has since become the default for Ruff, so we can remove it

Comment on lines -181 to +182
"TCH", # manage type checking blocks
"TC", # manage type checking blocks
Copy link
Member Author

@flying-sheep flying-sheep Jan 13, 2025

Choose a reason for hiding this comment

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

This has been renamed by Ruff

Comment on lines 178 to 179
raise KeyError(
"'{key!r}' not found in view of {self.attrname}"
) # Make sure it exists before bothering with a copy
msg = f"'{key!r}' not found in view of {self.attrname}"
raise KeyError(msg) # Make sure it exists before bothering with a copy
Copy link
Member Author

Choose a reason for hiding this comment

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

I spotted this error: There was an f missing, so this error message was pretty useless

add_note(e, f"for option {repr(option)}")
add_note(e, f"for option {option!r}")
Copy link
Member Author

@flying-sheep flying-sheep Jan 13, 2025

Choose a reason for hiding this comment

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

I changed this to use the format specifier !r instead of repr. (and did the same ~2 other times)

Comment on lines -11 to +12
from anndata import AnnData, ImplicitModificationWarning, read_h5ad, read_loom
from anndata import AnnData, ImplicitModificationWarning, read_h5ad
from anndata.io import read_loom
Copy link
Member Author

@flying-sheep flying-sheep Jan 13, 2025

Choose a reason for hiding this comment

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

Independent driveby fix, sorry!

@flying-sheep flying-sheep merged commit 9120c4d into main Jan 16, 2025
14 of 16 checks passed
@flying-sheep flying-sheep deleted the pa/ruff-0-9-em branch January 16, 2025 07:55
Copy link

lumberbot-app bot commented Jan 16, 2025

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout 0.11.x
git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 9120c4db9fdbaebc523ead259728e678bb802c4a
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #1825: (chore): Update to Ruff 0.9 and add EM lints'
  1. Push to a named branch:
git push YOURFORK 0.11.x:auto-backport-of-pr-1825-on-0.11.x
  1. Create a PR against branch 0.11.x, I would have named this PR:

"Backport PR #1825 on branch 0.11.x ((chore): Update to Ruff 0.9 and add EM lints)"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove the Still Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free to suggest an improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants