Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
quickbrett opened this issue Oct 1, 2023 · 7 comments
Closed

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

quickbrett opened this issue Oct 1, 2023 · 7 comments

Comments

@quickbrett
Copy link

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!

@molinav
Copy link
Member

molinav commented Oct 1, 2023

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

@quickbrett
Copy link
Author

I'm using the following versions:

  • matplotlib 3.7.3
  • numpy 1.25.2
  • basemap 1.3.8

@moritzhuetten
Copy link

@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.

@molinav
Copy link
Member

molinav commented Oct 2, 2023

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.

molinav added a commit that referenced this issue Oct 2, 2023
@molinav
Copy link
Member

molinav commented Oct 2, 2023

@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.

@quickbrett
Copy link
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!

@molinav
Copy link
Member

molinav commented Nov 19, 2023

@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).

@molinav molinav closed this as completed Nov 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants