Skip to content

0-dimensional array error in NumPy >2.4.0 #203

Description

@paddyroddy

Describe the bug

We are encountering an issue in GLASS where in Python >3.12 we're getting

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[1], line 25
     21 # basic parameters of the simulation
     22 nside = lmax = 256
     23 
     24 # set up CAMB parameters for matter angular power spectrum
---> 25 pars = camb.set_params(
     26     H0=100 * h,
     27     omch2=Oc * h**2,
     28     ombh2=Ob * h**2,

File ~/work/glass/glass/.nox/examples/lib/python3.14/site-packages/camb/camb.py:187, in set_params(cp, verbose, **params)
    185 do_set(cp.DarkEnergy.set_params)
    186 do_set(cp.Reion.set_extra_params)
--> 187 do_set(cp.set_cosmology)
    188 do_set(cp.set_matter_power)
    189 do_set(cp.set_for_lmax)

File ~/work/glass/glass/.nox/examples/lib/python3.14/site-packages/camb/camb.py:179, in set_params.<locals>.do_set(setter)
    177 if verbose:
    178     logger.warning(f"Calling {setter.__name__}(**{kwargs})")
--> 179 setter(**kwargs)

File ~/work/glass/glass/.nox/examples/lib/python3.14/site-packages/camb/model.py:691, in CAMBparams.set_cosmology(self, H0, ombh2, omch2, omk, cosmomc_theta, thetastar, neutrino_hierarchy, num_massive_neutrinos, mnu, nnu, YHe, meffsterile, standard_neutrino_neff, TCMB, tau, zrei, Alens, bbn_predictor, theta_H0_range, setter_H0)
    689         self.bbn_predictor = bbn_predictor or bbn.get_predictor()
    690     YHe = self.bbn_predictor.Y_He(ombh2 * (constants.COBE_CMBTemp / TCMB) ** 3, nnu - standard_neutrino_neff)
--> 691 self.YHe = YHe
    692 self.TCMB = TCMB
    693 self.ombh2 = ombh2

TypeError: only 0-dimensional arrays can be converted to Python scalars

This appears to have come from a change in NumPy 2.4.0. This is only appearing in later Python versions because NumPy 2.5.0 because it drops support for Python 3.11.

To Reproduce

Passes

uv run --isolated --with "camb" --with "numpy==2.3.5" python -c "import camb; camb.set_params(H0=70)"

Fails

uv run --isolated --with "camb" --with "numpy==2.4.1" python -c "import camb; camb.set_params(H0=70)"

(2.4.0 release was yanked due to backwards compatibility issues)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions