cta-observatory / ctapipe

Low-level data processing pipeline software for CTAO or similar arrays of Imaging Atmospheric Cherenkov Telescopes
https://ctapipe.readthedocs.org
BSD 3-Clause "New" or "Revised" License
65 stars 269 forks source link

Import error for ctapipe.io after updating to numpy 2.02 #2621

Closed GernotMaier closed 2 months ago

GernotMaier commented 2 months ago

Describe the bug from ctapipe.io import write_table throws an ImportError after updating to numpy 2.02

To Reproduce Steps to reproduce the behavior:


>>> from ctapipe.io import write_table
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/maierg/micromamba/envs/simtools-dev/lib/python3.11/site-packages/ctapipe/io/__init__.py", line 17, in <module>
    from .simteleventsource import SimTelEventSource
  File "/Users/maierg/micromamba/envs/simtools-dev/lib/python3.11/site-packages/ctapipe/io/simteleventsource.py", line 22, in <module>
    from ..calib.camera.gainselection import GainChannel, GainSelector
  File "/Users/maierg/micromamba/envs/simtools-dev/lib/python3.11/site-packages/ctapipe/calib/__init__.py", line 5, in <module>
    from .camera import CameraCalibrator, GainSelector
  File "/Users/maierg/micromamba/envs/simtools-dev/lib/python3.11/site-packages/ctapipe/calib/camera/__init__.py", line 6, in <module>
    from .calibrator import CameraCalibrator  # noqa: F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/maierg/micromamba/envs/simtools-dev/lib/python3.11/site-packages/ctapipe/calib/camera/calibrator.py", line 18, in <module>
    from ctapipe.image.extractor import ImageExtractor
  File "/Users/maierg/micromamba/envs/simtools-dev/lib/python3.11/site-packages/ctapipe/image/__init__.py", line 43, in <module>
    from .muon import (
  File "/Users/maierg/micromamba/envs/simtools-dev/lib/python3.11/site-packages/ctapipe/image/muon/__init__.py", line 7, in <module>
    from .fitting import kundu_chaudhuri_circle_fit
  File "/Users/maierg/micromamba/envs/simtools-dev/lib/python3.11/site-packages/ctapipe/image/muon/fitting.py", line 3, in <module>
    from iminuit import Minuit
  File "/Users/maierg/micromamba/envs/simtools-dev/lib/python3.11/site-packages/iminuit/__init__.py", line 24, in <module>
    from iminuit.minuit import Minuit
  File "/Users/maierg/micromamba/envs/simtools-dev/lib/python3.11/site-packages/iminuit/minuit.py", line 6, in <module>
    from iminuit import util as mutil
  File "/Users/maierg/micromamba/envs/simtools-dev/lib/python3.11/site-packages/iminuit/util.py", line 11, in <module>
    from iminuit import _repr_html, _repr_text, _deprecated
  File "/Users/maierg/micromamba/envs/simtools-dev/lib/python3.11/site-packages/iminuit/_deprecated.py", line 2, in <module>
    from numpy import VisibleDeprecationWarning
ImportError: cannot import name 'VisibleDeprecationWarning' from 'numpy' (/Users/maierg/micromamba/envs/simtools-dev/lib/python3.11/site-packages/numpy/__init__.py)

**Expected behavior**

no error.

**Supporting information**

**Additional context**
maxnoe commented 2 months ago

It looks like you only updated numpy and not minuit?

There are definitely tests covering the code that is throwing the error here.

Does this happen in a fresh environment? It might be that old minuit versions were not compatible with numpy 2.0 but didn't specify so in their dependencies.

maxnoe commented 2 months ago

Side note: we really should make the imports in io lazy. Importing half of ctapipe for write_table is not great.

GernotMaier commented 2 months ago

This is after running a micromamba update -f environment.yml on an existing environment. Let me try to generate a fresh environment to see if somehow minuit was not updated.

maxnoe commented 2 months ago

Fyi: the first iminuit version to support numpy 2.0 is 2.26 from June:

https://scikit-hep.org/iminuit/changelog.html#june-03-2024

GernotMaier commented 2 months ago

OK - there is no error when installing a fresh environment. So this is then likely an issue of mamba when updating an env.

I therefore suggest to close this issue.

maxnoe commented 2 months ago

It's an issue of the dependency specification of the iminuit package, nothing much mamba can do about it.