SciTools / cf-units

Units of measure as required by the Climate and Forecast (CF) Metadata Conventions
https://cf-units.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
64 stars 46 forks source link

cf-units wheel on pypi not compatible with numpy2 #443

Open heikoklein opened 6 days ago

heikoklein commented 6 days ago

🐛 Bug Report

Installing numpy-2 together with cf-units from pip is possible, but when running it, the following error is given:

venv/lib/python3.11/site-packages/iris/common/mixin.py:10: in <module>
    import cf_units
venv/lib/python3.11/site-packages/cf_units/__init__.py:23: in <module>
    from cf_units import _udunits2 as _ud
cf_units/_udunits2.pyx:1: in init cf_units._udunits2
    ???
E   ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject

How to Reproduce

Steps to reproduce the behaviour:

  1. pip install "numpy>=2"
  2. pip install cf-units
  3. pip list
    Package                Version
    ---------------------- -------
    antlr4-python3-runtime 4.7.2
    cf-units               3.2.0
    cftime                 1.6.4
    Jinja2                 3.1.4
    MarkupSafe             2.1.5
    numpy                  2.1.1
    pip                    22.0.2
    setuptools             59.6.0
  4. python -mcf_units
    Traceback (most recent call last):
    File "/usr/lib/python3.10/runpy.py", line 187, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
    File "/usr/lib/python3.10/runpy.py", line 146, in _get_module_details
    return _get_module_details(pkg_main_name, error)
    File "/usr/lib/python3.10/runpy.py", line 110, in _get_module_details
    __import__(pkg_name)
    File "/home/heikok/cfunits2/lib/python3.10/site-packages/cf_units/__init__.py", line 23, in <module>
    from cf_units import _udunits2 as _ud
    File "cf_units/_udunits2.pyx", line 1, in init cf_units._udunits2
    ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject

    Expected Behaviour

    cf-units should work together with numpy2. or cf-units should be marked incompatible with numpy2

Environment

ocefpaf commented 6 days ago

Needs https://github.com/SciTools/cf-units/pull/427 In a way, past builds will require a numpy<2 pin to keep working.