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

MAINT: Fix NumPy deprecation warnings #312

Merged
merged 3 commits into from
Mar 23, 2021

Conversation

bocklund
Copy link
Collaborator

@bocklund bocklund commented Mar 9, 2021

NumPy 1.20 deprecated the use of np.int, np.float, np.complex, ... (see here) which are type aliases that shadow the built-in types int, float, complex, ...

This PR was the result of 3 regex replaces on .py, .pyx, and .pxd files:

  1. \bnp.int\bnp.int_
  2. \bnp.float\bnp.float_
  3. \bnp.complex\bnp.complex_

These aliases have been around a long time (they are present in our minimum NumPy version 1.13 - tested on NumPy 1.13.3) so this change is backwards compatible. The trailing _ versions no longer shadow built-in types and keeping the suffixed versions allows us to find/replace these in the future (compared to built-in types, which we cannot).

For future reference: pytest -v pycalphad -W error::DeprecationWarning can be used to raise errors on DeprecationWarnings. Doing this resulted in 70 tests failing before this PR. Now no tests fail.

Used regex `\bnp.float\b` -> `float` - the boundary commands keep you
from matching legitimate usages of NumPy data types like `np.int32` or
`np.float64_t`

See https://numpy.org/devdocs/release/1.20.0-notes.html#using-the-aliases-of-builtin-types-like-np-int-is-deprecated
for more details

`pytest -v pycalphad -W error::DeprecationWarning` resulted in 70 tests
failing before this PR. Now no tests fail.
This PR was the result of 3 regex replaces on .py, .pyx, and .pxd files:

`\bnp.int\b` -> `np.int_`
`\bnp.float\b` -> `np.float_`
`\bnp.complex\b` -> `np.complex_`

The trailing `_` versions no longer alias built-in types and keeping
the suffixed versions allows us to find/replace these in the future
(compared to built-in types, which we cannot).

`pytest -v pycalphad -W error::DeprecationWarning` resulted in 70 tests
failing before this PR. Now no tests fail.

See https://numpy.org/devdocs/release/1.20.0-notes.html#using-the-aliases-of-builtin-types-like-np-int-is-deprecated
for more details
@codecov
Copy link

codecov bot commented Mar 9, 2021

Codecov Report

Merging #312 (0c76345) into develop (5038950) will not change coverage.
The diff coverage is 83.33%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop     #312   +/-   ##
========================================
  Coverage    86.78%   86.78%           
========================================
  Files           46       46           
  Lines         4464     4464           
========================================
  Hits          3874     3874           
  Misses         590      590           
Impacted Files Coverage Δ
pycalphad/model.py 91.28% <0.00%> (ø)
pycalphad/core/utils.py 89.71% <66.66%> (ø)
pycalphad/core/calculate.py 85.27% <100.00%> (ø)
pycalphad/core/halton.py 95.00% <100.00%> (ø)
pycalphad/plot/eqplot.py 69.56% <100.00%> (ø)
pycalphad/tests/test_energy.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5038950...0c76345. Read the comment docs.

@bocklund bocklund merged commit a0fee2b into pycalphad:develop Mar 23, 2021
@bocklund bocklund deleted the fix-deprecation-warnings branch November 7, 2021 00:12
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.

None yet

2 participants