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

fix(binaryfile): avoid numpy deprecation warnings #1868

Merged
merged 3 commits into from
Jul 12, 2023

Conversation

wpbonelli
Copy link
Member

@wpbonelli wpbonelli commented Jul 9, 2023

In the future, numpy will stop treating arrays with 1 element and dimension >0 as scalars. Use .item() to access the single element.

This may need to be fixed elsewhere in the codebase, this is the only place I have seen warnings from recently.

@codecov
Copy link

codecov bot commented Jul 9, 2023

Codecov Report

Merging #1868 (57f6dba) into develop (a84d885) will not change coverage.
The diff coverage is 100.0%.

@@           Coverage Diff           @@
##           develop   #1868   +/-   ##
=======================================
  Coverage     72.2%   72.2%           
=======================================
  Files          257     257           
  Lines        56226   56226           
=======================================
  Hits         40621   40621           
  Misses       15605   15605           
Impacted Files Coverage Δ
flopy/utils/binaryfile.py 80.0% <100.0%> (ø)
flopy/utils/gridutil.py 98.4% <100.0%> (ø)

@wpbonelli wpbonelli marked this pull request as ready for review July 12, 2023 00:03
@wpbonelli wpbonelli requested a review from mwtoews July 12, 2023 00:03
@wpbonelli
Copy link
Member Author

I took a brief look through the repo and the warnings raised by autotests and don't see this anywhere else. Will keep an eye out for more though

@mwtoews
Copy link
Contributor

mwtoews commented Jul 12, 2023

Thanks, I was considering addressing this new warning, you beat me to it! And agree that using .item() is a good approach. Also, keep in mind that new NumPy releases only support Python 3.9 or later, so new deprecation warnings are not visible with Python 3.8 runs.

Missed one from a different package, however:

test_gridutil.py: 7442 warnings
/home/runner/work/flopy/flopy/flopy/utils/gridutil.py:91: DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)
top[n] = tp

@wpbonelli
Copy link
Member Author

wpbonelli commented Jul 12, 2023

Thanks @mwtoews I did not realize this

new NumPy releases only support Python 3.9 or later, so new deprecation warnings are not visible with Python 3.8 runs

Fixed the one in gridutil and added type hints to the ndarray params in the get_disu_kwargs() signature

@wpbonelli wpbonelli merged commit 90f87f2 into modflowpy:develop Jul 12, 2023
@wpbonelli wpbonelli deleted the warnings branch July 12, 2023 18:47
wpbonelli added a commit that referenced this pull request Aug 25, 2023
* use ndarray.item() to retrieve single elements
* update gridutil get_disu_kwargs() docstrings
@wpbonelli wpbonelli mentioned this pull request Aug 25, 2023
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