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: switch to ruff, numpy compat fixes, ignore known test warnings #2124

Merged
merged 1 commit into from
Mar 14, 2024

Conversation

wpbonelli
Copy link
Member

@wpbonelli wpbonelli commented Mar 14, 2024

  • switch to ruff from black, isort, flake8, pylint, keep (mostly) the same settings
  • apply some suggested linting/formatting rules, ignore others in pyproject.toml
  • run ruff check --select NPY201 as suggested here, replace deprecated syntax
    • np.float_ -> np.float64
    • np.NaN -> np.nan
  • ignore well-known python-dateutil and pandas warnings

Copy link

codecov bot commented Mar 14, 2024

Codecov Report

Attention: Patch coverage is 69.23077% with 32 lines in your changes are missing coverage. Please review.

Project coverage is 73.1%. Comparing base (5ec612a) to head (ce14e25).

Additional details and impacted files
@@            Coverage Diff            @@
##           develop   #2124     +/-   ##
=========================================
- Coverage     73.1%   73.1%   -0.1%     
=========================================
  Files          259     259             
  Lines        59513   59511      -2     
=========================================
- Hits         43517   43514      -3     
- Misses       15996   15997      +1     
Files Coverage Δ
flopy/export/longnames.py 100.0% <ø> (ø)
flopy/export/unitsformat.py 100.0% <ø> (ø)
flopy/export/vtk.py 79.8% <100.0%> (ø)
flopy/mbase.py 69.9% <100.0%> (ø)
flopy/mf6/coordinates/modeldimensions.py 79.0% <ø> (ø)
flopy/mf6/data/mfdata.py 72.9% <100.0%> (ø)
flopy/mf6/data/mfdataplist.py 74.3% <ø> (ø)
flopy/mf6/data/mfdatastorage.py 71.2% <100.0%> (ø)
flopy/mf6/data/mffileaccess.py 71.3% <ø> (ø)
flopy/mf6/mfbase.py 82.6% <ø> (ø)
... and 57 more

@wpbonelli wpbonelli marked this pull request as ready for review March 14, 2024 18:00
@wpbonelli wpbonelli requested a review from langevin-usgs March 14, 2024 18:02
Copy link
Contributor

@langevin-usgs langevin-usgs left a comment

Choose a reason for hiding this comment

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

These changes all seem good to me. I like the cleanup of the bool comparisons and removal of unnecessary f-strings.

@wpbonelli
Copy link
Member Author

wpbonelli commented Mar 14, 2024

Ruff will do "safe" cleanups like those automatically with ruff check --fix, and can do the comparisons too with --unsafe-fixes, https://docs.astral.sh/ruff/faq/#ruff-tried-to-fix-something-but-it-broke-my-code-whats-going-on

@wpbonelli wpbonelli merged commit b142b08 into modflowpy:develop Mar 14, 2024
24 checks passed
@wpbonelli wpbonelli deleted the ruff branch March 14, 2024 19:43
@wpbonelli wpbonelli mentioned this pull request Apr 15, 2024
5 tasks
wpbonelli added a commit to wpbonelli/flopy that referenced this pull request Jun 17, 2024
The docs for `np.where()` (https://numpy.org/doc/stable/reference/generated/numpy.where.html) suggest to prefer `nonzero()` over `where()` without `x` and `y` arguments. In the spirit of defensive programming I included `np.asarray(cond)` even where `cond` is already an array.

This PR also fixes a bug I introduced in the model splitter in modflowpy#2124: while E711 (https://www.flake8rules.com/rules/E711.html) dictates comparisons to `None` should use identity rather than equality, this rule should not be applied to NumPy array selection conditions as it will change the semantics:

```shell
>>> a = np.array([None, None])
>>> a[a != None]
array([], dtype=object)
>>> a[a is not None]
array([[None, None]], dtype=object)
```

Unrelatedly, mark `test_mt3d.py::test_mfnwt_keat_uzf()` slow, it should not be included in smoke tests.
wpbonelli added a commit to wpbonelli/flopy that referenced this pull request Jun 17, 2024
The docs for `np.where()` (https://numpy.org/doc/stable/reference/generated/numpy.where.html) suggest to prefer `nonzero()` over `where()` without `x` and `y` arguments. In the spirit of defensive programming I included `np.asarray(cond)` even where `cond` is already an array.

This PR also fixes a bug I introduced in the model splitter in modflowpy#2124: while E711 (https://www.flake8rules.com/rules/E711.html) dictates comparisons to `None` should use identity rather than equality, this rule should not be applied to NumPy array selection conditions as it will change the semantics:

```shell
>>> a = np.array([None, None])
>>> a[a != None]
array([], dtype=object)
>>> a[a is not None]
array([[None, None]], dtype=object)
```

Unrelatedly, mark `test_mt3d.py::test_mfnwt_keat_uzf()` slow, it should not be included in smoke tests.
wpbonelli added a commit that referenced this pull request Jun 17, 2024
The docs for `np.where()` (https://numpy.org/doc/stable/reference/generated/numpy.where.html) suggest to prefer `nonzero()` over `where()` without `x` and `y` arguments. In the spirit of defensive programming I included `np.asarray(cond)` even where `cond` is already an array.

This PR also fixes a bug I introduced in the model splitter in #2124: while E711 (https://www.flake8rules.com/rules/E711.html) dictates comparisons to `None` should use identity rather than equality, this rule should not be applied to NumPy array selection conditions as it will change the semantics:

>>> a = np.array([None, None])
>>> a[a != None]
array([], dtype=object)
>>> a[a is not None]
array([[None, None]], dtype=object)

Unrelatedly, mark `test_mt3d.py::test_mfnwt_keat_uzf()` slow, it should not be included in smoke tests (this was causing the optional dependency CI tests to fail due to timeout). And clean up some unused imports in `conftest.py`.
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.

2 participants