-
Notifications
You must be signed in to change notification settings - Fork 20
Action ruff checks #416
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
base: main
Are you sure you want to change the base?
Action ruff checks #416
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -145,7 +145,6 @@ preview = false | |
|
|
||
| [tool.ruff.lint] | ||
| ignore = [ | ||
|
|
||
| # flake8-annotations (ANN) | ||
| # https://docs.astral.sh/ruff/rules/#flake8-annotations-ann | ||
| "ANN001", # Missing type annotation for function argument {name} | ||
|
|
@@ -156,21 +155,6 @@ ignore = [ | |
| "ANN204", # Missing return type annotation for special method {name} | ||
|
|
||
| "ARG002", # Unused method argument: {name} | ||
| "ARG003", # Unused class method argument: {name} | ||
|
|
||
| # flake8-bugbear (B) | ||
| # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b | ||
| "B028", # No explicit stacklevel keyword argument found | ||
|
|
||
| # flake8-comprehensions (C4) | ||
| # https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4 | ||
| "C405", # Unnecessary {obj_type} literal (rewrite as a set literal) | ||
| "C419", # Unnecessary list comprehension | ||
|
|
||
| # flake8-commas (COM) | ||
| # https://docs.astral.sh/ruff/rules/#flake8-commas-com | ||
| "COM812", # Trailing comma missing. | ||
| "COM819", # Trailing comma prohibited. | ||
|
|
||
| # pydocstyle (D) | ||
| # https://docs.astral.sh/ruff/rules/#pydocstyle-d | ||
|
|
@@ -185,46 +169,12 @@ ignore = [ | |
| # https://docs.astral.sh/ruff/rules/#eradicate-era | ||
| "ERA001", # Found commented-out code | ||
|
|
||
| # flake8-boolean-trap (FBT) | ||
| # https://docs.astral.sh/ruff/rules/#flake8-boolean-trap-fbt | ||
| "FBT002", # Boolean default positional argument in function definition | ||
|
|
||
| # flake8-implicit-str-concat (ISC) | ||
| # https://docs.astral.sh/ruff/rules/single-line-implicit-string-concatenation/ | ||
| # NOTE: This rule may cause conflicts when used with "ruff format". | ||
| "ISC001", # Implicitly concatenate string literals on one line. | ||
|
|
||
| # pep8-naming (N) | ||
| # https://docs.astral.sh/ruff/rules/#pep8-naming-n | ||
| "N801", # Class name {name} should use CapWords convention | ||
| "PT011", | ||
|
|
||
| # Refactor (R) | ||
| # https://docs.astral.sh/ruff/rules/#refactor-r | ||
| "PLR2004", # Magic value used in comparison, consider replacing {value} with a constant variable | ||
|
|
||
| # flake8-pytest-style (PT) | ||
| # https://docs.astral.sh/ruff/rules/#flake8-pytest-style-pt | ||
| "PT009", # Use a regular assert instead of unittest-style {assertion} | ||
| "PT027", # Use pytest.raises instead of unittest-style {assertion} | ||
|
|
||
| # flake8-return (RET) | ||
| # https://docs.astral.sh/ruff/rules/#flake8-return-ret | ||
| "RET504", # Unnecessary assignment to {name} before return statement | ||
|
|
||
| # Ruff-specific rules (RUF) | ||
| # https://docs.astral.sh/ruff/rules/#ruff-specific-rules-ruf | ||
| "RUF005", # Consider {expression} instead of concatenation | ||
| "RUF012", # Mutable class attributes should be annotated with typing.ClassVar | ||
|
|
||
| # flake8-self (SLF) | ||
| # https://docs.astral.sh/ruff/rules/#flake8-self-slf | ||
| "SLF001", # Private member accessed: {access} | ||
| "PLR2004", | ||
|
|
||
| # flake8-print (T20) | ||
| # https://docs.astral.sh/ruff/rules/#flake8-print-t20 | ||
| "T201", # print found | ||
|
|
||
| ] | ||
| "S101", # Use of assert detected. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You needed to add this one, presumably because you've been converting the tests to use PyTest? If you, could you move this exception down to the file-specific exceptions for |
||
| ] | ||
| preview = false | ||
| select = [ | ||
| "ALL", | ||
|
|
@@ -239,13 +189,20 @@ known-first-party = ["iris"] | |
|
|
||
| [tool.ruff.lint.per-file-ignores] | ||
| # All test scripts | ||
|
|
||
| "src/stratify/tests/performance.py" = [ | ||
| "T201", # print found | ||
| ] | ||
| "setup.py" = [ | ||
| "T201", # print found | ||
| "RUF012", # Mutable class attributes should be annotated with typing.ClassVar | ||
| ] | ||
| # Change to match specific package path: | ||
| "lib/iris/tests/*.py" = [ | ||
| "src/stratify/tests/*.py" = [ | ||
| # https://docs.astral.sh/ruff/rules/undocumented-public-module/ | ||
| "D100", # Missing docstring in public module | ||
| "D205", # 1 blank line required between summary line and description | ||
| "D401", # 1 First line of docstring should be in imperative mood | ||
| "SLF001", # Private member accessed: {access} | ||
| ] | ||
|
|
||
| [tool.ruff.lint.pydocstyle] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,7 +91,8 @@ def interpolate_conservative(z_target, z_src, fz_src, axis=-1): | |
| ) | ||
| raise ValueError(msg.format(tuple(dat_shape), tuple(src_shape))) | ||
|
|
||
| if z_src.shape[-1] != 2: | ||
| shape_2 = 2 | ||
| if z_src.shape[-1] != shape_2: | ||
| msg = "Unexpected source and target bounds shape. shape[-1] != 2" | ||
| raise ValueError(msg) | ||
|
|
||
|
|
@@ -100,8 +101,8 @@ def interpolate_conservative(z_target, z_src, fz_src, axis=-1): | |
|
|
||
| # src_data | ||
| bdims = list(range(fz_src.ndim - (z_src.ndim - 1))) | ||
| data_vdims = [ind for ind in range(fz_src.ndim) if ind not in (bdims + [axis])] | ||
| data_transpose = bdims + [axis] + data_vdims | ||
| data_vdims = [ind for ind in range(fz_src.ndim) if ind not in ([*bdims, axis])] | ||
| data_transpose = [*bdims, axis, *data_vdims] | ||
| fz_src_reshaped = np.transpose(fz_src, data_transpose) | ||
| fz_src_orig = list(fz_src_reshaped.shape) | ||
| shape = ( | ||
|
|
@@ -113,21 +114,24 @@ def interpolate_conservative(z_target, z_src, fz_src, axis=-1): | |
|
|
||
| # Define our src and target bounds in a consistent way. | ||
| # [axis_interpolation, z_varying, 2] | ||
| vdims = list(set(range(z_src.ndim)) - set([axis_relative])) | ||
| z_src_reshaped = np.transpose(z_src, [axis_relative] + vdims) | ||
| z_target_reshaped = np.transpose(z_target, [axis_relative] + vdims) | ||
| # vdims = list(set(range(z_src.ndim)) - set([axis_relative])) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Commented code |
||
| vdims = list(set(range(z_src.ndim)) - {axis_relative}) | ||
| z_src_reshaped = np.transpose(z_src, [axis_relative, *vdims]) | ||
| z_target_reshaped = np.transpose(z_target, [axis_relative, *vdims]) | ||
|
|
||
| shape = int(np.prod(z_src_reshaped.shape[1:-1])) | ||
| z_src_reshaped = z_src_reshaped.reshape( | ||
| [z_src_reshaped.shape[0], shape, z_src_reshaped.shape[-1]] | ||
| [z_src_reshaped.shape[0], shape, z_src_reshaped.shape[-1]], | ||
| ) | ||
| shape = int(np.prod(z_target_reshaped.shape[1:-1])) | ||
| z_target_reshaped = z_target_reshaped.reshape( | ||
| [z_target_reshaped.shape[0], shape, z_target_reshaped.shape[-1]] | ||
| [z_target_reshaped.shape[0], shape, z_target_reshaped.shape[-1]], | ||
| ) | ||
|
|
||
| result = conservative_interpolation( | ||
| z_src_reshaped, z_target_reshaped, fz_src_reshaped | ||
| z_src_reshaped, | ||
| z_target_reshaped, | ||
| fz_src_reshaped, | ||
| ) | ||
|
|
||
| # Turn the result into a shape consistent with the source. | ||
|
|
@@ -136,5 +140,5 @@ def interpolate_conservative(z_target, z_src, fz_src, axis=-1): | |
| shape[len(bdims)] = z_target.shape[axis_relative] | ||
| result = result.reshape(shape) | ||
| invert_transpose = [data_transpose.index(ind) for ind in list(range(result.ndim))] | ||
| result = result.transpose(invert_transpose) | ||
| return result | ||
| # result = result.transpose(invert_transpose) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Commented code |
||
| return result.transpose(invert_transpose) | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |||||||||||||||||||
| import stratify | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| def src_data(shape=(400, 500, 100), lazy=False): | ||||||||||||||||||||
| def src_data(shape=(400, 500, 100)): | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not quite sure of the design of this module, but python-stratify/src/stratify/tests/performance.py Lines 44 to 45 in 612de10
python-stratify/src/stratify/tests/performance.py Lines 18 to 24 in 612de10
|
||||||||||||||||||||
| z = np.tile(np.linspace(0, 100, shape[-1]), np.prod(shape[:2])).reshape(shape) | ||||||||||||||||||||
| if lazy: | ||||||||||||||||||||
| fz = da.arange(np.prod(shape), dtype=np.float64).reshape(shape) | ||||||||||||||||||||
|
|
||||||||||||||||||||
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.
It's cool that Ruff works on notebooks. It's also cool the improved pattern it found for randomness. 👍