Skip to content

AttributeError: module 'numpy' has no attribute 'float'. #589

Closed

Description

@quickbrett

This small example retrurns an error

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap

fig = plt.figure(figsize=(8, 6), edgecolor="w")
m = Basemap(projection="moll", resolution=None, lat_0=0, lon_0=0)
m.drawmapboundary()
m.shadedrelief(scale=0.2)

The error message:

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#deprecations

I belive, the wrong attribute is used in packages/basemap/src/mpl_toolkits/basemap/__init__.py, master branch, line 4186.

This small patch works for me:

4186c4186
<                     x1 = np.array(ny*[0.5*(self.xmax + self.xmin)],np.float)
---
>                     x1 = np.array(ny*[0.5*(self.xmax + self.xmin)],np.float32)

Thanks for the great package!

Activity

  1. molinav commented on Oct 1, 2023

    @molinav
    Member

    Thanks for pointing the bug! Just out of curiosity, which numpy version are you using?

  2. quickbrett commented on Oct 1, 2023

    @quickbrett
    Author

    I'm using the following versions:

    • matplotlib 3.7.3
    • numpy 1.25.2
    • basemap 1.3.8
  3. moritzhuetten commented on Oct 1, 2023

    @moritzhuetten

    @quickbrett thanks for raising this issue and proposing the fix and @molinav thanks for maintaining this still great package. I actually got the same error, I think it is related to the latest numpy versions.

  4. molinav commented on Oct 2, 2023

    @molinav
    Member

    It seems that numpy.float was removed with its release 1.24.0 (https://numpy.org/devdocs/release/1.24.0-notes.html). I will replace it with the Python builtin float as suggested in the link.

    Hopefully I can get some time soon to start a basic unit test collection, because these issues would be identified immediately with the automatic tests.

  5. molinav commented on Oct 2, 2023

    @molinav
    Member

    @quickbrett I just added the patch in a hotfix branch (1.3.9), your small example now works after the correction. I took this moment to correct all the references to numpy.float that I found in the whole library, mostly replaced with numpy.float64.

    I am not sure when I will release 1.3.9, maybe I will do a couple of bugfixes more that are still around before tagging.

  6. quickbrett commented on Oct 3, 2023

    @quickbrett
    Author

    @molinav I installes the hotfix branch

    pip install git+https://github.com/matplotlib/basemap@hotfix-1.3.9#subdirectory=packages/basemap
    

    Hence I'm using the following package versions (pip list):

    • basemap 1.3.9
    • numpy 1.25.2
    • matplotlib 3.7.3

    I tested the new version with a few simple examples and it worked for me.

    Thanks!

  7. molinav commented on Nov 19, 2023

    @molinav
    Member

    @quickbrett I have just added a couple of unit tests for Basemap.shadedrelief based on your snippet, so I am finally closing this issue. The bugfix will come with basemap 1.3.9 (hopefully soon).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions