Skip to content

Action ruff checks#416

Open
HGWright wants to merge 1 commit intoSciTools:mainfrom
HGWright:ruff-check
Open

Action ruff checks#416
HGWright wants to merge 1 commit intoSciTools:mainfrom
HGWright:ruff-check

Conversation

@HGWright
Copy link
Contributor

🚀 Pull Request

Description

From #277. We have been tracking the ignored checks for Ruff. This PR goes through and actions all of the applicable checks and ignores the ones we cant deal with yet, mainly around type hinting and documentation.

Part of these checks is moving from references to unittest to pytest, and from assertEqual to just regular assert statements


Copy link
Contributor

@scitools-ci scitools-ci bot left a comment

Choose a reason for hiding this comment

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

Templating

This PR includes changes that may be worth sharing via templating. For each file listed below, please either:

  • Action the suggestion via a pull request editing/adding the relevant file in the SciTools/.github templates/ directory. 1
  • Raise an issue against the SciTools/.github repo for the above action if you really don't have 10mins spare right now. Include an assignee, to avoid it being forgotten.
  • Dismiss the suggestion if the changes are not suitable for templating.

You will need to dismiss this review before this PR can be merged. Recommend the reviewer does this as their final action before merging, as this text will continually update as commits come in.

Templated files

The following changed files are templated:

Template candidates

The following changed files are not currently templated, but their parent directories suggest they may be good candidates for a new template to be created:

Footnotes

  1. Include this text in the PR body to avoid any notifications about applying the template changes back to the source repo!
    @scitools-templating: please no update notification on: python-stratify

@trexfeathers trexfeathers self-assigned this Mar 19, 2026
Copy link
Contributor

@trexfeathers trexfeathers left a comment

Choose a reason for hiding this comment

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

Thanks @HGWright, some requests for you

output_array[:] = np.inf if direction > 0 else -np.inf


class TestColumnInterpolation(unittest.TestCase):
Copy link
Contributor

Choose a reason for hiding this comment

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

Why have you done this in some places but not in others? test_bounded_vinterp.py still has some examples.

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]))
Copy link
Contributor

Choose a reason for hiding this comment

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

Commented code

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Commented code

Copy link
Contributor

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. 👍

"T201", # print found

]
"S101", # Use of assert detected.
Copy link
Contributor

Choose a reason for hiding this comment

The 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 src/stratify/tests/*.py?



def src_data(shape=(400, 500, 100), lazy=False):
def src_data(shape=(400, 500, 100)):
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not quite sure of the design of this module, but lazy is very much still used. Seems like Ruff made a mistake?

lazy = "lazy" in sys.argv[1:]
interp_and_extrap(shape=(500, 600, 100), lazy=lazy)

def interp_and_extrap(
shape,
lazy,
interp=stratify.INTERPOLATE_LINEAR,
extrap=stratify.EXTRAPOLATE_NEAREST,
):
z, fz = src_data(shape, lazy)

Copy link
Contributor

Choose a reason for hiding this comment

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

This file has a lot more unittest left in it than test_vinterp does.

  • Still inheriting from unittest.TestCase
  • Still calling unittest.main() at the bottom
  • Maybe other stuff I've missed?

I'm guessing you went this way because the tests in this file include setUp() methods, which are a unittest thing so the tests cannot run without unittest?

Anyway it's confusing to have these different states; I would prefer everything or nothing; options:

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

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants