pythonnumpypipfloating-pointattributeerror

Dipy - Attribute Error: AttributeError: module 'numpy' has no attribute 'float'


I'm using the Dipy library and when I was attempting to import one of the functions I got this Attribute Error:

AttributeError: module 'numpy' has no attribute 'float'.
`np.float` was a deprecated alias for the builtin `float`. To avoid this error in existing code, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:https://numpy.org/devdocs/release/1.20.0-notes.html#deprecationshttps://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

However I don't see any use of np.float anywhere in the traceback or in my code base.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[15], line 15
     12 import matplotlib.pylab as plt
     13 import dataframe_image as dfi
---> 15 from data.nifti_dataset import resample_nifti
     16 # from data.base_dataset import _roll2center_crop
     17 # from fpdf import FPDF
     18 # from IPython import display
   (...)
     27 # from utils import metrics
     28 # from utils import myocardial_strain

File /data/__init__.py:4
      2 import numpy as np
      3 import nibabel as nib
----> 4 from dipy.align.reslice import reslice
      7 def resample_nifti(nifti, order=1, mode='nearest',
      8                    in_plane_resolution_mm=1.25, slice_thickness_mm=None, number_of_slices=None):
     10     resolution = np.array(nifti.header.get_zooms()[:3] + (1,))

File /lib/python3.8/site-packages/dipy/align/__init__.py:27
     16 VerbosityLevels = Bunch(NONE=0, STATUS=1, DIAGNOSE=2, DEBUG=3)
     17 r""" VerbosityLevels
     18 This enum defines the four levels of verbosity we use in the align
     19 module.
   (...)
     24 DEBUG : print as much information as possible to isolate the cause of a bug.
     25 """
---> 27 from dipy.align._public import (syn_registration, register_dwi_to_template, # noqa
     28                                 write_mapping, read_mapping, resample,
     29                                 center_of_mass, translation, rigid, affine,
     30                                 affine_registration, register_series,
     31                                 register_dwi_series, streamline_registration)
     33 __all__ = ["syn_registration", "register_dwi_to_template",
     34            "write_mapping", "read_mapping", "resample",
     35            "center_of_mass", "translation", "rigid", "affine",
     36            "affine_registration", "register_series",
     37            "register_dwi_series", "streamline_registration"]

File /lib/python3.8/site-packages/dipy/align/_public.py:26
     16 from dipy.align.imaffine import (transform_centers_of_mass,
     17                                  AffineMap,
     18                                  MutualInformationMetric,
     19                                  AffineRegistration)
     21 from dipy.align.transforms import (TranslationTransform3D,
     22                                    RigidTransform3D,
     23                                    AffineTransform3D)
---> 26 import dipy.core.gradients as dpg
     27 import  as dpd
     28 from dipy.align.streamlinear import StreamlineLinearRegistration

File /lib/python3.8/site-packages/dipy/core/gradients.py:10
      8 from dipy.core.onetime import auto_attr
      9 from dipy.core.geometry import vector_norm, vec2vec_rotmat
---> 10 from dipy.core.sphere import disperse_charges, HemiSphere
     12 from dipy.utils.deprecator import deprecate_with_version
     15 WATER_GYROMAGNETIC_RATIO = 267.513e6  # 1/(sT)

File /lib/python3.8/site-packages/dipy/core/sphere.py:776
    774 unit_octahedron = Sphere(xyz=octahedron_vertices, faces=octahedron_faces)
    775 unit_icosahedron = Sphere(xyz=icosahedron_vertices, faces=icosahedron_faces)
--> 776 hemi_icosahedron = HemiSphere.from_sphere(unit_icosahedron)

File /lib/python3.8/site-packages/dipy/core/sphere.py:342, in HemiSphere.from_sphere(klass, sphere, tol)
    339 u/classmethod
    340 def from_sphere(klass, sphere, tol=1e-5):
    341     """Create instance from a Sphere"""
--> 342     return klass(theta=sphere.theta, phi=sphere.phi,
    343                  edges=sphere.edges, faces=sphere.faces, tol=tol)

File lib/python3.8/site-packages/dipy/core/sphere.py:328, in HemiSphere.__init__(self, x, y, z, theta, phi, xyz, faces, edges, tol)
    325 """Create a HemiSphere from points"""
    327 sphere = Sphere(x=x, y=y, z=z, theta=theta, phi=phi, xyz=xyz)
--> 328 uniq_vertices, mapping = remove_similar_vertices(sphere.vertices, tol,
    329                                                  return_mapping=True)
    330 uniq_vertices *= 1 - 2*(uniq_vertices[:, -1:] < 0)
    331 if faces is not None:

File dipy/reconst/recspeed.pyx:97, in dipy.reconst.recspeed.remove_similar_vertices()

File /lib/python3.8/site-packages/numpy/__init__.py:305, in __getattr__(attr)
    300     warnings.warn(
    301         f"In the future `np.{attr}` will be defined as the "
    302         "corresponding NumPy scalar.", FutureWarning, stacklevel=2)
    304 if attr in __former_attrs__:
--> 305     raise AttributeError(__former_attrs__[attr])
    307 # Importing Tester requires importing all of UnitTest which is not a
    308 # cheap import Since it is mainly used in test suits, we lazy import it
    309 # here to save on the order of 10 ms of import time for most users
    310 #
    311 # The previous way Tester was imported also had a side effect of adding
    312 # the full `numpy.testing` namespace
    313 if attr == 'testing':
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[15], line 15
     12 import matplotlib.pylab as plt
     13 import dataframe_image as dfi
---> 15 from data.nifti_dataset import resample_nifti
     16 # from data.base_dataset import _roll2center_crop
     17 # from fpdf import FPDF
     18 # from IPython import display
   (...)
     27 # from utils import metrics
     28 # from utils import myocardial_strain

File /data/__init__.py:4
      2 import numpy as np
      3 import nibabel as nib
----> 4 from dipy.align.reslice import reslice
      7 def resample_nifti(nifti, order=1, mode='nearest',
      8                    in_plane_resolution_mm=1.25, slice_thickness_mm=None, number_of_slices=None):
     10     resolution = np.array(nifti.header.get_zooms()[:3] + (1,))

File /lib/python3.8/site-packages/dipy/align/__init__.py:27
     16 VerbosityLevels = Bunch(NONE=0, STATUS=1, DIAGNOSE=2, DEBUG=3)
     17 r""" VerbosityLevels
     18 This enum defines the four levels of verbosity we use in the align
     19 module.
   (...)
     24 DEBUG : print as much information as possible to isolate the cause of a bug.
     25 """
---> 27 from dipy.align._public import (syn_registration, register_dwi_to_template, # noqa
     28                                 write_mapping, read_mapping, resample,
     29                                 center_of_mass, translation, rigid, affine,
     30                                 affine_registration, register_series,
     31                                 register_dwi_series, streamline_registration)
     33 __all__ = ["syn_registration", "register_dwi_to_template",
     34            "write_mapping", "read_mapping", "resample",
     35            "center_of_mass", "translation", "rigid", "affine",
     36            "affine_registration", "register_series",
     37            "register_dwi_series", "streamline_registration"]

File /lib/python3.8/site-packages/dipy/align/_public.py:26
     16 from dipy.align.imaffine import (transform_centers_of_mass,
     17                                  AffineMap,
     18                                  MutualInformationMetric,
     19                                  AffineRegistration)
     21 from dipy.align.transforms import (TranslationTransform3D,
     22                                    RigidTransform3D,
     23                                    AffineTransform3D)
---> 26 import dipy.core.gradients as dpg
     27 import  as dpd
     28 from dipy.align.streamlinear import StreamlineLinearRegistration

File /lib/python3.8/site-packages/dipy/core/gradients.py:10
      8 from dipy.core.onetime import auto_attr
      9 from dipy.core.geometry import vector_norm, vec2vec_rotmat
---> 10 from dipy.core.sphere import disperse_charges, HemiSphere
     12 from dipy.utils.deprecator import deprecate_with_version
     15 WATER_GYROMAGNETIC_RATIO = 267.513e6  # 1/(sT)

File /lib/python3.8/site-packages/dipy/core/sphere.py:776
    774 unit_octahedron = Sphere(xyz=octahedron_vertices, faces=octahedron_faces)
    775 unit_icosahedron = Sphere(xyz=icosahedron_vertices, faces=icosahedron_faces)
--> 776 hemi_icosahedron = HemiSphere.from_sphere(unit_icosahedron)

File /lib/python3.8/site-packages/dipy/core/sphere.py:342, in HemiSphere.from_sphere(klass, sphere, tol)
    339 u/classmethod
    340 def from_sphere(klass, sphere, tol=1e-5):
    341     """Create instance from a Sphere"""
--> 342     return klass(theta=sphere.theta, phi=sphere.phi,
    343                  edges=sphere.edges, faces=sphere.faces, tol=tol)

File /lib/python3.8/site-packages/dipy/core/sphere.py:328, in HemiSphere.__init__(self, x, y, z, theta, phi, xyz, faces, edges, tol)
    325 """Create a HemiSphere from points"""
    327 sphere = Sphere(x=x, y=y, z=z, theta=theta, phi=phi, xyz=xyz)
--> 328 uniq_vertices, mapping = remove_similar_vertices(sphere.vertices, tol,
    329                                                  return_mapping=True)
    330 uniq_vertices *= 1 - 2*(uniq_vertices[:, -1:] < 0)
    331 if faces is not None:

File dipy/reconst/recspeed.pyx:97, in dipy.reconst.recspeed.remove_similar_vertices()

File /lib/python3.8/site-packages/numpy/__init__.py:305, in __getattr__(attr)
    300     warnings.warn(
    301         f"In the future `np.{attr}` will be defined as the "
    302         "corresponding NumPy scalar.", FutureWarning, stacklevel=2)
    304 if attr in __former_attrs__:
--> 305     raise AttributeError(__former_attrs__[attr])
    307 # Importing Tester requires importing all of UnitTest which is not a
    308 # cheap import Since it is mainly used in test suits, we lazy import it
    309 # here to save on the order of 10 ms of import time for most users
    310 #
    311 # The previous way Tester was imported also had a side effect of adding
    312 # the full `numpy.testing` namespace
    313 if attr == 'testing':dipy.datadipy.data

I attempted to search the code base using VS code and couldn't find a single use of np.float anywhere so I don't understand how this error could occur.

I am using numpy 1.24.4 and dipy 1.3.0


Solution

  • You are using python 3.8. But, it only supports python 3.9 or above.

    enter image description here

    https://pypi.org/project/dipy/