Skip to content

Conversation

@mrmundt
Copy link
Contributor

@mrmundt mrmundt commented Jun 17, 2024

Fixes #3290

Summary/Motivation:

Add in the updates for NumPy 2.

Changes proposed in this PR:

  • Change defaults / check for removed attributes
  • Update tests

Legal Acknowledgement

By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

Copy link
Member

@jsiirola jsiirola left a comment

Choose a reason for hiding this comment

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

One (mostly stylistic) question

@mrmundt
Copy link
Contributor Author

mrmundt commented Jun 17, 2024

FYI for anyone watching this PR: it needs some work on the NL writer's processing of NumPy representations. @jsiirola is going to look at it soon.

@mrmundt mrmundt requested a review from jsiirola June 17, 2024 18:50
Comment on lines -19 to +22
numpy_bool_names.append('bool_')
if numpy.__version__[0] == '2':
numpy_bool_names.append('bool')
else:
numpy_bool_names.append('bool_')
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you check version here, but everywhere else you use hasattr?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because John added that one...

Copy link
Contributor Author

@mrmundt mrmundt Jun 24, 2024

Choose a reason for hiding this comment

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

Oh but also, I can answer - this is a forwards-compatible one. bool and bool_ are both valid in NumPy 2, whereas bool does not exist in older NumPys. The other ones are forcing backwards compatibility.

# numpy build (it depends on platform and version).
# Register them only if they are present
if hasattr(np, 'float_'):
# Prepend to preserve previous functionality

Choose a reason for hiding this comment

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

Note that float_/complex_ were simple aliases to float64/complex128, so it is not necessary to handle them for numpy 1.x, just dropping them is fully backwards compatible.

dbrnz added a commit to AnatomicMaps/flatmap-maker that referenced this pull request Aug 15, 2024
@jsiirola jsiirola mentioned this pull request Aug 18, 2024
@mrmundt mrmundt deleted the numpy-update branch March 10, 2025 21:09
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.

Pyomo is not compatible with Numpy 2.0.0

5 participants