Skip to content

Numpy2 #93

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

Merged
merged 3 commits into from
Dec 19, 2024
Merged

Numpy2 #93

merged 3 commits into from
Dec 19, 2024

Conversation

henrikjacobsenfys
Copy link
Member

Updated to use the newest versions of numpy and pint. Dropped Python 3.9, and included 3.13.

I had a lot of trouble with this part of parameter.py, on line 163

    @property
    def value(self) -> numbers.Number:
        """
        Get the value of self as a Number.

        :return: Value of self without unit.
        """
        if self._callback.fget is not None:
            existing_value = self._callback.fget()
            if existing_value != self._scalar.value:
                self._scalar.value = existing_value
        return self._scalar.value

The problem was that the mock did not have a _callback.fget() function. In this case, it returns something else: <MagicMock name='mock.fget()' id='2183984899984'>
The comparison with self._scalar.value used to simply give False, since they are clearly not identical. In Numpy 2, the result is ambiguous and gives an error
I can't quite tell if we need to update value to check if _callback.fget() actually produces a number, since it seems to only be an issue when mocking.
I've updated the tests to mock _callback.fget() as needed, but perhaps it's better to do it more generally?

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

This pull request does not contain a valid label. Please add one of the following labels: ['chore', 'fix', 'bugfix', 'bug', 'enhancement', 'feature', 'dependencies', 'documentation']

@henrikjacobsenfys henrikjacobsenfys changed the base branch from master to develop December 17, 2024 15:13
@henrikjacobsenfys henrikjacobsenfys added the chore PR label label Dec 17, 2024
Copy link
Member

@rozyczko rozyczko left a comment

Choose a reason for hiding this comment

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

The changes look benign, and do what needs to be done.
Agreed with the mocking issue - this is pre-existing and we need to find a general solution for proper mocking of those cases.

@henrikjacobsenfys henrikjacobsenfys merged commit cbe2372 into develop Dec 19, 2024
60 checks passed
@henrikjacobsenfys henrikjacobsenfys deleted the numpy2-new branch December 19, 2024 09:40
elindgren pushed a commit that referenced this pull request Mar 3, 2025
Added support for Numpy 2, dropped support for Python 3.9, added support for Python 3.13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore PR label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants