navis-org / navis

Python library for analysis of neuroanatomical data.
https://navis.readthedocs.io
GNU General Public License v3.0
80 stars 29 forks source link

New numpy version leads to AttributeError #115

Closed jakobtroidl closed 10 months ago

jakobtroidl commented 1 year ago

Hi @schlegelp,

I just spent some time debugging and thought this might be helpful for some other users.

It seems like Navis is incompatible with numpy v1.24.0. However, everything works fine with numpy v1.23.5. For v1.24.0 version, I get the following error message.

 File "/Users/jakobtroidl/Desktop/neuronal-motifs/neuronal_motifs/server/vimo/lib/python3.10/site-packages/navis/core/__init__.py", line 17, in <module>
    from .mesh import MeshNeuron
  File "/Users/jakobtroidl/Desktop/neuronal-motifs/neuronal_motifs/server/vimo/lib/python3.10/site-packages/navis/core/mesh.py", line 31, in <module>
    from .. import utils, config, meshes, conversion, graph
  File "/Users/jakobtroidl/Desktop/neuronal-motifs/neuronal_motifs/server/vimo/lib/python3.10/site-packages/navis/conversion/__init__.py", line 15, in <module>
    from .meshing import voxels2mesh
  File "/Users/jakobtroidl/Desktop/neuronal-motifs/neuronal_motifs/server/vimo/lib/python3.10/site-packages/navis/conversion/meshing.py", line 436, in <module>
    def _voxels_to_matrix(voxels, fill=False, pad=1, dtype=np.bool):
  File "/Users/jakobtroidl/Desktop/neuronal-motifs/neuronal_motifs/server/vimo/lib/python3.10/site-packages/numpy/__init__.py", line 284, in __getattr__
    raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'bool'. Did you mean: 'bool_'?

Let me know if I should provide more details. Best, Jakob

clbarnes commented 1 year ago

The latest numpy has a bunch of deprecations expiring. np.bool was deprecated in 1.20 in favour of python's native bool (which is interpreted by numpy to a different type with a different implementation, which can be referred to using np.bool_, but that's another matter...). https://numpy.org/devdocs/release/1.20.0-notes.html#using-the-aliases-of-builtin-types-like-np-int-is-deprecated

tl;dr we just need to replace all references to np.bool with bool, I think!

The fix, replacing the np.bool reference with a plain bool, seems to already have been implemented in master https://github.com/navis-org/navis/commit/da2c0b33f2fb916087740e8e844775b2d0a2585b so all will be fine on the next release.

jakobtroidl commented 1 year ago

Amazing, I'll look out for the new release. Thanks for letting me know ;)

schlegelp commented 1 year ago

Thanks for the digging, Jakob! I did remove np.bool a while back but we also haven't had a new release in almost 6 months and we're overdue for one. I'll check if anything needs wrapping up before we do but for now you could install navis from Github to get a working version:

$ pip3 install git+https://github.com/navis-org/navis@master
schlegelp commented 1 year ago

I just released navis version 1.4.0 which should fix the issues with numpy. Let us know if this does the trick! Please see the change log for other changes.

schlegelp commented 10 months ago

Closing assuming this is solved.