cherab / core

The core source repository for the Cherab project.
https://www.cherab.info
Other
44 stars 24 forks source link

SciPy deprecation warning for scipy.integrate.cumtrapz #436

Closed vsnever closed 3 months ago

vsnever commented 3 months ago

When calculating with the Beam, SciPy 1.12 raises DeprecationWarning:

DeprecationWarning: 'scipy.integrate.cumtrapz' is deprecated in favour of 'scipy.integrate.cumulative_trapezoid' and will be removed in SciPy 1.14.0

Therefore, we need to replace deprecated cumtrapz() with the cumulative_trapezoid() in SingeRayAttenuator._beam_attenuation(). However, the new name was only introduced in SciPy 1.7, and the tests fail in the Python 3.7 + oldest-supported-numpy environment.

I suggest using:

try:
    from scipy.integrate import cumulative_trapezoid
except ImportError:
    from scipy.integrate import cumtrapz as cumulative_trapezoid
vsnever commented 3 months ago

Fixed in #437.

leferi99 commented 2 weeks ago

I am getting an ImportError with Scipy 1.14:

File /usr/local/lib/python3.10/dist-packages/cherab/core/model/attenuator/init.py:1 from .singleray import SingleRayAttenuator File /usr/local/lib/python3.10/dist-packages/cherab/core/model/attenuator/singleray.pyx:21, in init cherab.core.model.attenuator.singleray() ImportError: cannot import name cumtrapz

I tried adding

try:
    from scipy.integrate import cumulative_trapezoid
except ImportError:
    from scipy.integrate import cumtrapz as cumulative_trapezoid

to the file singleray.pyx instead of the from scipy.integrate import cumtrapz but it still gave the same error after that. I am not too familiar with how the C and Python interacts (if this problem even relates to that) so I would appreciate some help.

vsnever commented 2 weeks ago

Hi @leferi99, The issue is already fixed in the development branch. Have you recompile/reinstall Cherab after applying the local fix? Also try installing Cherab 1.5 Release Candidate 2 with pip install cherab==1.5.0rc2 and see if the warning still appears.

leferi99 commented 2 weeks ago

Thank you @vsnever this fixed it. I used the simple pip install so I still had the release version, not the development.