-
Notifications
You must be signed in to change notification settings - Fork 55
Update numpy, pint, python, scipy, versioneer #903
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
base: master
Are you sure you want to change the base?
Conversation
…emove scikit-learn cap
… not available any longer in recent numpy releases
… in setup.py for now
…ype strings now defined centrally in utils.numba_tools)
… itself for now; prevent overflows in osc.scaling_params service in single precision; experimentally update pythonpackage.yml workflow to use python 3.12
…) and reintroduce python-3.10 matrix configuration into workflow
…tomography w constraint
| has_uncertainties = True | ||
| std_devs = obj.std_dev | ||
| obj = obj.nominal_value | ||
| elif isinstance(obj, np.ndarray) and np.issubsctype(obj, AffineScalarFunc): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doubt this ever worked the way it was intended to, i.e., managed to only detect an ndarray that was created with uncertainties.
The reason is that np.issubsctype(obj, AffineScalarFunc) would determine the dtype of obj, but because AffineScalarFunc isn't a NumPy scalar subclass, the ndarray obj would have dtype=np.object_. Hence, the check couldn't detect whether the elements are AffineScalarFunc instances (and not, e.g., PISA Params, and would always return True. As shown below, np.issubsctype(np.object_, AffineScalarFunc) is True, as is np.issubdtype(np.object_, AffineScalarFunc)---probably because np.obj2sctype(AffineScalarFunc) yields np.object_.
Applying this check to an array with uncertainties created in two different ways:
>>> import numpy as np
>>> from pisa.core.param import Param
>>> from uncertainties import ufloat, unumpy
>>> from uncertainties.core import AffineScalarFunc
>>> arr1 = unumpy.uarray([1, 2], [0.01, 0.002])
>>> print(arr1.dtype)
object
>>> isinstance(arr1, np.ndarray)
True
>>> arr2 = np.array([ufloat(1, 0.1), ufloat(2, 0.002)])
>>> print(arr2.dtype)
object
>>> isinstance(arr2, np.ndarray)
True
>>> u1 = ufloat(1, 0.1)
>>> isinstance(u1, AffineScalarFunc)
True
>>> np.issubsctype(arr1, AffineScalarFunc)
True
>>> np.issubsctype(arr2, AffineScalarFunc)
True
>>> # but also:
>>> p = Param(name="x", value=0.1, prior=None, range=[0,1], is_fixed=True)
>>> arr3 = np.array([p, p])
>>> np.issubsctype(arr3, AffineScalarFunc)
TrueThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On a related note, in old numpy (in my case 1.22.4), np.issubdtype(arr1.dtype, AffineScalarFunc) still worked, while now in numpy 2.3.5 it doesn't any longer (raises ValueError: dtype attribute is not a valid dtype instance for the second argument, AffineScalarFunc).
All of the remaining dependencies are brought up to date (also see the linked issues). If I am not mistaken, none of these changes are expected to break existing PISA installations, and indeed don't seem to be doing so (as confirmed by successful unit and service tests in environments of mine without updated dependencies).
Note: Select "squash and merge" if and when this is merged to create a single commit.