raysect / source

The main source repository for the Raysect project.
http://www.raysect.org
BSD 3-Clause "New" or "Revised" License
88 stars 23 forks source link

Deprecation warnings with numpy 1.20 #382

Closed jacklovell closed 3 years ago

jacklovell commented 3 years ago

Numpy 1.20 has deprecated np.bool, np.int etc: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

This means Cherab and raysect scripts using 2D observers now display the following warning:

DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.

It looks like the only place these deprecations exist are in sampler2d.pyx:

(cherab) jlovell@freia028 Cherab> grep -r "np\.bool[^0-9]" --include="*.py" --include="*.pyx" --include="*.pxd" raysect
raysect/raysect/optical/observer/sampler2d.pyx:            self._mask = value.astype(np.bool)
raysect/raysect/optical/observer/sampler2d.pyx:            self.mask = np.ones(pixels, dtype=np.bool)
raysect/raysect/optical/observer/sampler2d.pyx:            self._mask = value.astype(np.bool)
raysect/raysect/optical/observer/sampler2d.pyx:            self.mask = np.ones(pixels, dtype=np.bool)
raysect/raysect/optical/observer/sampler2d.pyx:            self.mask = np.ones(pixels, dtype=np.bool)
raysect/raysect/optical/observer/sampler2d.pyx:            self._mask = value.astype(np.bool)
raysect/raysect/optical/observer/sampler2d.pyx:            self.mask = np.ones(pixels, dtype=np.bool)
raysect/raysect/optical/observer/sampler2d.pyx:            self.mask = np.ones(pixels, dtype=np.bool)
raysect/raysect/optical/observer/sampler2d.pyx:            self._mask = value.astype(np.bool)
raysect/raysect/optical/observer/sampler2d.pyx:            self.mask = np.ones(pixels, dtype=np.bool)
raysect/raysect/optical/observer/sampler2d.pyx:            self.mask = np.ones(pixels, dtype=np.bool)

These instances should have np.bool replaced with bool.

vsnever commented 3 years ago

Thanks, @jacklovell. It looks like the code that triggers these warnings was added by me. I'll fix it.